 |
|
haharich
V2EX member #336831, joined on 2018-07-28 22:50:58 +08:00
|
 |
Per haharich's settings, the topics list is only visible after you sign in |
Deals info, including closed deals, is not hidden
haharich's recent replies
这应该算是异步编程的知识了
1 、.await 不会阻塞当前线程主要是指当前线程如果此时有其他异步任务( Future )还是可以同时运行其他异步任务,并不会阻塞在只运行当前异步任务中(因为当前异步任务需要时间去完成),从现在的代码看,只有 hello_world()这个一个 Future ,所以体现不出来,假设还有一个 hello_world1()的 Future ,里面等待时间 2s ,然后不使用 block_on()去驱动这两个 Future ,而是使用 tokio 异步库的 join!()去并发驱动这两个 Future 就能看到其中一个在等待的同时可以运行另一个 Future 并输出日志(注意 thread::sleep(ten_millis) 需要换成异步然后 await 的方式,因为它是阻塞的,不然体现不出效果)
3 、所以在当前的调用栈上,用 .await 就是要等待当前异步任务完成才能执行后面的逻辑,肯定是先输出 kitty ,hello_cat()的 Future 完成后,才会执行 hello_dog 输出 snoopy ,可以简单认为这里说的不阻塞跟当前调用栈没关系
请教下月嫂一般是做哪些事,有月嫂还有必要婆婆/丈母娘过来吗,是不是需要给月嫂提供住宿