expression
Runtime lifetime and joined work
Join tasks that must complete before destroying their runtime. Async tasks may be dropped during shutdown; already running blocking closures cannot be forcibly aborted. This example completes its finite work before releasing the runtime. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): 21 Common mistake: Relying on runtime drop as a guarantee that every task completed its business work.
Formal Syntax & Structure
rust syntaxrust
drop(runtime)Working Example
Example Snippetrust
fn main() { let rt = tokio::runtime::Builder::new_current_thread().build().unwrap(); let result = rt.block_on(async { tokio::spawn(async { 21 }).await.unwrap() }); drop(rt); println!("{result}");}