Skip to main content

BlockingHandle

Struct BlockingHandle 

Source
pub struct BlockingHandle<R> { /* private fields */ }
Expand description

Handle returned by TaskSupervisor::spawn_blocking.

Awaiting BlockingHandle::join blocks until the OS-thread task produces a value. Dropping the handle without joining does not cancel the task — it continues to run on the blocking thread pool but the result is discarded.

A panic inside the closure is captured and returned as BlockingError::Panicked rather than propagating to the caller.

Implementations§

Source§

impl<R> BlockingHandle<R>

Source

pub async fn join(self) -> Result<R, BlockingError>

Await the task result.

§Errors
Source

pub fn try_join(self) -> Result<Result<R, BlockingError>, Self>

Non-blocking poll: return the result if the task has already finished, or None if it is still running.

This is the BlockingHandle equivalent of FutureExt::now_or_never on a tokio::task::JoinHandle. Call this inside a synchronous context (e.g., between agent turns) to apply a completed background result without blocking.

The handle is consumed on success. If the task is not yet done, the handle is returned as Err(self) so the caller can re-store it.

§Examples
async fn example(mut handle: BlockingHandle<u32>) {
    // Try to get the result without blocking.
    match handle.try_join() {
        Ok(result) => println!("done: {result:?}"),
        Err(handle) => {
            // Task still running — `handle` is returned for re-storage.
            drop(handle);
        }
    }
}
§Errors

Returns Err(self) when the task has not yet produced a result (still running). The inner Ok(Err(BlockingError::...)) variants are returned when the task panicked or the supervisor was dropped before the task completed.

Source

pub fn abort(&self)

Abort the underlying task immediately.

Auto Trait Implementations§

§

impl<R> Freeze for BlockingHandle<R>

§

impl<R> !RefUnwindSafe for BlockingHandle<R>

§

impl<R> Send for BlockingHandle<R>
where R: Send,

§

impl<R> Sync for BlockingHandle<R>
where R: Send,

§

impl<R> Unpin for BlockingHandle<R>

§

impl<R> UnsafeUnpin for BlockingHandle<R>

§

impl<R> !UnwindSafe for BlockingHandle<R>

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> 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, 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