-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
spawn_blocking: this program silently fails #2116
Comments
Not exactly. I think it just cannot get a chance to run before the main thread exits. use tokio::time::delay_for;
use std::time::Duration;
#[tokio::main]
async fn main()
{
tokio::task::spawn_blocking( || eprintln!("hello") );
delay_for(Duration::from_millis(100)).await;
println!("100 ms have elapsed");
}
// hello
// 100 ms have elapsed |
Hi @Gowee
Sorry, I meant to say that it will not run until it's awaited on. I think you misinterpret my report. Let me by analogy show you a function that returns a
I'm suggesting that |
@njaard so I agree that would be handy but the issue is that there are cases where you don't want to actually handle the |
@LucioFranco I think the current approach is so error prone that it's worthwhile to add it anyway. Anyway, we can do |
@njaard looks like if you change your code to use std its the same thing with no warning: So if that is the case I would think that this should be fixed in std then in tokio. Since, technically this is possible in std I don't think its worth while fixing here either. The big difference with std too is that you need to explicitly join the tread while tokio allows you await directly to do that. |
Closing in favor of #1830. |
Version
└── tokio v0.2.9
└── tokio-macros v0.2.3
Platform
Linux audax 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11) x86_64 GNU/Linux
Description
This program compiles without warnings:
Expected behavior
At compile time, I should get a warning saying that the function will run until it is awaited on.
Actual behavior
The program compiles cleanly but never (though correctly) runs the closure with the
eprintln!
.The text was updated successfully, but these errors were encountered: