Skip to content

Instantly share code, notes, and snippets.

@bltavares
Forked from justanotherdot/async-internal-spawn.rs
Last active September 20, 2020 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bltavares/cbddd771a2325c4cb15f1b8bc3f1d61c to your computer and use it in GitHub Desktop.
Save bltavares/cbddd771a2325c4cb15f1b8bc3f1d61c to your computer and use it in GitHub Desktop.
use async_std::task;
fn main() {
task::block_on(async move {
println!("outer");
task::spawn(async move {
println!("inner 1");
});
task::spawn(async move {
task::sleep(std::time::Duration::from_secs(1)).await;
println!("inner 2");
})
.await; // without this, will finish the main block before the tasks are executed
})
}
[package]
name = "async-internal-spawn"
version = "0.1.0"
authors = ["Ryan James Spencer <spencer.ryanjames@gmail.com>"]
edition = "2018"
[dependencies.async-std]
version = '1.6.2'
features = ['unstable']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment