41 ms·
I've encountered the "wait on async things from sync code" issue several times, too. I have found that something like `block_on` from either `futures` or `futur
by vlmutolo 6y ago
I've encountered the "wait on async things from sync code" issue several times, too. I have found that something like `block_on` from either `futures` or `futures_lite` often does the trick.
https://docs.rs/futures-lite/1.11.3/futures_lite/future/fn.block_on.html https://docs.rs/futures-lite/1.11.3/futures_lite/future/fn.b...
- boulos 6y agoRight, but depending on the tokio version (maybe) using block_on results in a hang or panic. I’ll see if futures_lite is any different, but I think it’s mostly on tokio’s side.
- masklinn 6y ago> depending on the tokio version (maybe) using block_on results in a hang or panic Isn't it mostly a function of what runtime you're using? `block_on` with a single-threaded runtime can't run tasks elsewhere (since there's only one thread which you're blocking) so depending on the version it would either hang (before detection of that situation was added) or panic, with an error message saying to use a multithreaded runtime. I completely agree that it's a pain in the ass though, especially since there are situations where tokio must be coerced into using anything but the basic scheduler (e.g. tests).