diff --git a/Cargo.toml b/Cargo.toml index 9098dcd..f394d0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,9 +9,14 @@ edition = "2021" # path = "src/examples/test_sync.rs" +# [[bin]] +# name = "test_async" +# path = "src/examples/test_async.rs" + + [[bin]] name = "test_async" -path = "src/examples/test_async.rs" +path = "src/examples/test_cb.rs" [[test]] diff --git a/src/examples/test_cb.rs b/src/examples/test_cb.rs new file mode 100644 index 0000000..3639d80 --- /dev/null +++ b/src/examples/test_cb.rs @@ -0,0 +1,34 @@ +use tokio::time::sleep; +use tokio::time::Duration; + +use futures::future::BoxFuture; + +fn test(val: u8) -> BoxFuture<'static, Result> { + Box::pin(async move { + println!("cbbbbb!!! {}", val); + Ok(true) + }) +} + +#[tokio::main] +async fn main() { + println!("test cb"); + + let mut cbb: Option BoxFuture<'static, Result>> = None; + + cbb = Some(test); + + tokio::spawn(cbb.unwrap()(1)); + + tokio::spawn(test(1)); + + tokio::spawn(test(2)); + + tokio::spawn(test(3)); + + tokio::spawn(test(4)); + + tokio::spawn(test(5)); + + sleep(Duration::from_secs(2)).await +}