Skip to main content

AbortableTask

Trait AbortableTask 

Source
pub trait AbortableTask: Future<Output = Result<(), Box<dyn Error + Send>>> + Send {
    // Required method
    fn abort(&self);
}
Expand description

A future that represents a running task which can be cancelled.

Awaiting an AbortableTask blocks until the task completes and yields Ok(()) on success or an error if the task panicked or otherwise failed.

Call abort to request cancellation. The exact semantics are runtime-dependent:

  • Tokio — calls JoinHandle::abort, which cancels the task at the next .await point.
  • std thread — drops the join handle and marks the task as finished so that awaiting the future resolves immediately. The underlying thread may continue running, but the caller is no longer blocked on it.

Required Methods§

Source

fn abort(&self)

Requests cancellation of the task.

After calling abort, awaiting this future will resolve without waiting for the spawned work to finish. Calling abort on an already-completed task is a no-op.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§