expression

Transfer an owned queue permit

Reserve with ownership of a sender handle, allowing the permit to outlive a borrow of the original sender. Moving the permit to a task transfers responsibility for using or releasing the slot. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): 12 true Common mistake: Assuming reserve_owned leaves the consumed sender variable usable.

Formal Syntax & Structure

rust syntaxrust
sender.reserve_owned().await

Working Example

Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() {    let (tx, mut rx) = tokio::sync::mpsc::channel(1);    let permit = tx.reserve_owned().await.unwrap();    let task = tokio::spawn(async move { drop(permit.send(12)); });    task.await.unwrap();    println!("{}", rx.recv().await.unwrap());    println!("{}", rx.recv().await.is_none());}
Rust Reference