Skip to main content

BlockingBridge

Struct BlockingBridge 

Source
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

Source

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.

Source

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).

Source

pub fn spawn<F>(&self, future: F) -> TaskHandle<F::Output>
where F: Future + Send + 'static, F::Output: Send + 'static,

Spawn future onto the captured runtime — spawn for a thread the runtime is not entered on.

Trait Implementations§

Source§

impl Clone for BlockingBridge

Source§

fn clone(&self) -> BlockingBridge

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more