如果你还在纠结这个问题,恭喜你,来对地方了!把下面这个sample code 的执行过程理解透彻了,那基本就明白异步到底是怎么回事儿了。今后写起async 就可以更加自信了,你说呢?
sample code
fn main() {
// Create the mini-tokio instance.
let mini_tokio = MiniTokio::new();
// Spawn the root task. All other tasks are spawned from the context of this
// root task. No work happens until `mini_tokio.run()` is called.
mini_tokio.spawn(async {
// Spawn a task
spawn(async {
// Wait for a little bit of time so that "world" is printed after
// "hello"
delay(Duration::from_millis(100