-
Version Platform Description [short summary of the bug] I tried this code: [code sample that causes the bug] async fn test_func() {
_ = tokio::task::spawn(async move {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
test_func().await;
});
}
#[tokio::main]
async fn main() {
test_func().await;
} I expected to see this happen: [explanation] Instead, this happened: [explanation]
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Unfortunately this is just a bad error message, and Tokio can do nothing to improve it. It's a Rust bug, not a Tokio bug. I've converted your bug report to a discussion so lets discuss workarounds. The usual workaround is to move the call to async fn test_func() {
test_func_spawn();
}
fn test_func_spawn() {
_ = tokio::task::spawn(async move {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
test_func().await;
});
}
#[tokio::main]
async fn main() {
test_func().await;
} or in your case just make fn test_func() {
_ = tokio::task::spawn(async move {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
test_func();
});
}
#[tokio::main]
async fn main() {
test_func();
} |
Beta Was this translation helpful? Give feedback.
Unfortunately this is just a bad error message, and Tokio can do nothing to improve it. It's a Rust bug, not a Tokio bug. I've converted your bug report to a discussion so lets discuss workarounds.
The usual workaround is to move the call to
tokio::spawn
into a non-async function:or in your case just make
test_func
non-async: