defer/
defer.rs

1use std::{thread, time::Duration};
2
3use microasync::{sync, join};
4use microasync_util::defer;
5
6
7fn main() {
8    println!("{}", sync(join!(test(), async { is_alive().await; "".to_owned() }))[0]);
9}
10
11async fn is_alive() {
12    println!("The runtime is NOT blocked by the test() function: This future runs *after* the poll\
13        to the test() function, so if this runs before test() is done, that means test() returned\
14        Poll::Pending and is not blocking.");
15}
16
17async fn test() -> String {
18    defer(|(s,)| {
19        thread::sleep(Duration::from_millis(2000));
20        s + "world"
21    }, ("Hello, ".to_owned(),)).await
22}