You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to run async code from a sync function, with actix_rt::main the future never ending it's execution, with tokio::main it works without problems.
Example code:
use tokio::runtime::Handle;use tokio::time::sleep;#[actix_rt::main]asyncfnmain(){call_sync();}pubfncall_sync(){let handle = Handle::current();let five = std::thread::spawn(move || {
handle.block_on(get_five_async())}).join().unwrap();println!("{five:?}");}pubasyncfnget_five_async() -> i32{sleep(core::time::Duration::from_millis(100)).await;5}
I minimized the code where I actually have this problem, an actix-web endpoint where I'm trying to block waiting for a future to resolve, in the real code the future never runs even with tokio::main macro, I'm doing something wrong or there is a compatibility issue?
The text was updated successfully, but these errors were encountered:
Guara92
changed the title
actix_rt::main is not compatible with tokio block_onactix_rt::main is not compatible with tokio block_onMar 12, 2022
I'll answer for myself, unfortunately this is not possible in a single-threaded runtime like actix-rt, the same problem also occurs with #[tokio::main(flavor="current_thread")].
Trying to run async code from a sync function, with
actix_rt::main
the future never ending it's execution, withtokio::main
it works without problems.Example code:
I minimized the code where I actually have this problem, an actix-web endpoint where I'm trying to block waiting for a future to resolve, in the real code the future never runs even with
tokio::main
macro, I'm doing something wrong or there is a compatibility issue?The text was updated successfully, but these errors were encountered: