pub struct BlockingBridge { /* private fields */ }Expand description
A capability, captured where the backend’s executor is reachable, to run async work from a plain blocking thread (iocsh, a REPL, a script thread).
block_on_sync answers “may I block here, now?” per call and can only
use whatever runtime is visible on the calling thread. This type answers
the reachability question once, at capture time, and
carries the answer to a thread the runtime is otherwise invisible from: a
tokio handle is thread-local state, so a blocking thread spawned before
it exists has no way to find it. The exec backend’s executor is
process-global, so there is nothing to carry and the bridge is a ZST —
which is what makes an API taking a BlockingBridge compile and work on
both backends, where one taking tokio::runtime::Handle pinned every
caller to tokio.
Implementations§
Source§impl BlockingBridge
impl BlockingBridge
Sourcepub fn capture() -> Self
pub fn capture() -> Self
Capture the current tokio runtime.
§Panics
Panics when no runtime is entered on this thread — call it on the async setup path (where the runtime is known), not on the blocking thread the bridge is being made for.
Sourcepub fn block_on<F: Future>(&self, fut: F) -> F::Output
pub fn block_on<F: Future>(&self, fut: F) -> F::Output
Drive fut to completion on this thread, with the captured runtime
entered so the future may spawn and use the reactor.
§Panics
Panics on a runtime worker thread: blocking one parks tasks that may
include the future’s own wakers (the same refusal block_on_sync
reports as a value).
Trait Implementations§
Source§impl Clone for BlockingBridge
impl Clone for BlockingBridge
Source§fn clone(&self) -> BlockingBridge
fn clone(&self) -> BlockingBridge
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more