我只能在我的牧场主 kubernetes 云中重现此问题。在本地运行良好。但是,如果我生成一个在循环中调用 sleep 的新线程。 Rocket 将挂起,我不知道为什么。
tokio::spawn(async move {
loop {
thread::sleep(Duration::from_secs(1));
}
});
这使得很难知道每 x 秒运行一些函数。
按照 @aleksander-krauze 在评论中的解释,使用 tokio::time::sleep 解决了这个问题。