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>
impl<R> BlockingHandle<R>
Sourcepub async fn join(self) -> Result<R, BlockingError>
pub async fn join(self) -> Result<R, BlockingError>
Await the task result.
§Errors
BlockingError::Panicked— the task closure panicked.BlockingError::SupervisorDropped— the task was aborted or the supervisor was dropped before a value was produced.
Sourcepub fn try_join(self) -> Result<Result<R, BlockingError>, Self>
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.