Skip to main content

wait_on

Function wait_on 

pub fn wait_on<F>(
    runtime: &Handle,
    future: F,
) -> Result<<F as Future>::Output, Error>
where F: Future + Send + 'static, <F as Future>::Output: Send + 'static,
Expand description

Run future on runtime and wait for its output on the calling thread.

The one way synchronous code calls into a runtime it does not drive — a daemon’s network, a service’s host — from a thread of its own: the future runs as a task of runtime, and the caller waits on a plain channel, outside any runtime. Unlike Runtime::block_on on a shared handle, the caller’s thread never enters runtime, so it may be any thread that owns no runtime. Async code awaits the future instead.

§Errors

Error::UiThread on a UI thread, Error::InsideRuntime in any runtime context (a worker of this crate’s runtime or of another one, runtime’s own included, where waiting would stall the tasks queued behind the caller, or deadlock a runtime with one worker), and Error::TaskFailed when the task panicked or runtime shut down before it finished.