【发布时间】:2021-04-02 01:10:05
【问题描述】:
当我在main 中调用do_update().await 时,它会打印出“Foo”,但循环似乎停止了,而不是阻止程序返回。这是什么原因?
async fn do_update() {
task::spawn(async {
let duration = Duration::from_millis(10);
let mut stream = tokio::time::interval(duration);
stream.tick().await;
loop {
println!("Foo");
stream.tick().await;
}
});
}
【问题讨论】:
-
另见Shouldn't a loop spawned in a thread print repeatedly?。多线程程序的概念通常适用于异步程序。
标签: asynchronous rust task