expression
Dropping JoinHandle detaches the task
Dropping the handle does not request cancellation. The task can continue while its runtime is alive. Use a separate completion signal in this demonstration; production code should normally retain a supervised lifecycle. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): 8 Common mistake: Assuming discarding a handle stops a task or guarantees cleanup.
Formal Syntax & Structure
rust syntaxrust
drop(handle)Working Example
Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() { let (tx, rx) = tokio::sync::oneshot::channel(); let task = tokio::spawn(async move { tx.send(8u32).unwrap(); }); drop(task); println!("{}", rx.await.unwrap());}