expression

JoinHandle::is_finished is a snapshot

Inspect whether a task has finished at that instant. The result does not retrieve the output, and a false result may immediately change. Await the handle for the result instead of spinning. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): false true Common mistake: Busy-waiting on is_finished inside an async function.

Formal Syntax & Structure

rust syntaxrust
handle.is_finished() -> bool

Working Example

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