pub struct TaskHandle<R, E> { /* private fields */ }Expand description
Handle for a task running outside the caller’s current stack.
TaskHandle is returned by thread-backed executors and services. Calling
Self::get blocks the current thread until the accepted task completes.
Awaiting the handle waits asynchronously for the same final task result.
§Type Parameters
R- The task success value.E- The task error value.
Implementations§
Source§impl<R, E> TaskHandle<R, E>
impl<R, E> TaskHandle<R, E>
Sourcepub fn get(self) -> Result<R, TaskExecutionError<E>>
pub fn get(self) -> Result<R, TaskExecutionError<E>>
Waits for the task to finish and returns its final result.
This method blocks the current thread until a result is available.
§Returns
Ok(R) if the task succeeds. If the accepted task returns Err(E),
panics, or is cancelled before producing a value, the corresponding
crate::TaskExecutionError is returned.
Sourcepub fn is_done(&self) -> bool
pub fn is_done(&self) -> bool
Returns whether the task has reported completion.
§Returns
true after the task runner has produced or abandoned its final result.
Sourcepub fn cancel(&self) -> bool
pub fn cancel(&self) -> bool
Attempts to cancel the task.
Cancellation can only win before the runner marks the task as started. It cannot interrupt a task that is already running on an OS thread.
§Returns
true if the task was cancelled before it started, or false if the
task was already running or completed.
Trait Implementations§
Source§impl<R, E> Future for TaskHandle<R, E>
impl<R, E> Future for TaskHandle<R, E>
Source§fn poll(
self: Pin<&mut TaskHandle<R, E>>,
cx: &mut Context<'_>,
) -> Poll<<TaskHandle<R, E> as Future>::Output>
fn poll( self: Pin<&mut TaskHandle<R, E>>, cx: &mut Context<'_>, ) -> Poll<<TaskHandle<R, E> as Future>::Output>
Polls this handle for the accepted task’s final result.