expression
AbortHandle: separate cancellation capability
Give another component the ability to request task cancellation without transferring the ability to await its output. Retain the original join handle to observe termination. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): true Common mistake: Assuming dropping an AbortHandle cancels the task.
Formal Syntax & Structure
rust syntaxrust
handle.abort_handle(); abort_handle.abort()Working Example
Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() { let task = tokio::spawn(std::future::pending::<()>()); let stop = task.abort_handle(); stop.abort(); println!("{}", task.await.unwrap_err().is_cancelled());}