expression

Abort and await cancellation

Request cancellation of a task and then await termination. An already completed task can still return successfully; a permanently pending future in this example is guaranteed not to complete normally. Abort is not rollback of earlier side effects. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): true Common mistake: Assuming abort synchronously completes cleanup or undoes external work.

Formal Syntax & Structure

rust syntaxrust
handle.abort(); handle.await

Working Example

Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() {    let task = tokio::spawn(std::future::pending::<u32>());    task.abort();    let err = task.await.unwrap_err();    println!("{}", err.is_cancelled());}
Rust Reference