-
Notifications
You must be signed in to change notification settings - Fork 341
Nested task_spawn with block_on is not working #760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Could you please clarify what "doesn't work"? Do you observe a panic or a lock? |
Either it's a lock or an infinite loop. The terminal hangs forever. This is the full example use async_std::task;
fn main() {
let t = task::spawn(async {
println!("parent task spawned");
let nested_t = task::spawn(async {
println!("nested task spawned");
});
task::block_on(nested_t); //this doesn't return
//nested_t.await; //this yields
});
task::block_on(t);
println!("never reaches here incase of nested block_on");
} |
|
I'm not sure "doesn't make sense" applies here. Yes in the above, simplified, for example it seems nonsensical but in most applications we don't have control over every library that is used or it is possible for some code path to be synchronous for other reasons. So if a library uses block_on anywhere in their code it becomes unusable in asynchronous code which is a bit of a bummer. And the same applies to block_on in a block_on too. |
Fixed in #799 |
Nested
block_on
works:Nested
task_spawn
withawait
works:but nested
task_spawn
withblock_on
doesn't work:Version:
async-std = "1.5.0"
Not sure if I'm doing something obviously wrong!
The text was updated successfully, but these errors were encountered: