1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#[macro_export]
macro_rules! nursery {
    ($body:expr) => {{
        let exec = smol::Executor::new();

        {
            // This allows the `spawn!` macro to access `exec` by name
            macro_rules! spawn {
                ($val:expr) => {
                    exec.spawn($val)
                };
            }

            exec.run(async { $body }).await
        }
    }};
}

#[cfg(test)]
mod test {
    use std::time::Duration;

    #[test]
    fn simple_nursery() {
        smol::future::block_on(async {
            nursery!({
                println!("test");

                spawn!(async move { println!("world") }).detach();
                smol::Timer::after(Duration::from_secs(1)).await;
            });
        });
    }
}