expression
Runtime Handle: access an existing scheduler
A handle can be copied by cloning and used to submit work to its runtime. It is not a replacement for retaining and driving the runtime itself. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): 11 Common mistake: Expecting a Handle to keep a dropped Runtime usable.
Formal Syntax & Structure
rust syntaxrust
Runtime::handle().clone(); Handle::spawn(future)Working Example
Example Snippetrust
fn main() { let rt = tokio::runtime::Builder::new_current_thread().build().unwrap(); let handle = rt.handle().clone(); let task = handle.spawn(async { 11 }); println!("{}", rt.block_on(task).unwrap());}