Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
XdoctorwhoZ committed Aug 2, 2024
1 parent c7eb55f commit ab95b61
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
34 changes: 34 additions & 0 deletions src/examples/test_cb.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use tokio::time::sleep;
use tokio::time::Duration;

use futures::future::BoxFuture;

fn test(val: u8) -> BoxFuture<'static, Result<bool, ()>> {
Box::pin(async move {
println!("cbbbbb!!! {}", val);
Ok(true)
})
}

#[tokio::main]
async fn main() {
println!("test cb");

let mut cbb: Option<fn(u8) -> BoxFuture<'static, Result<bool, ()>>> = 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
}

0 comments on commit ab95b61

Please sign in to comment.