[][src]Function catty::oneshot

pub fn oneshot<T: Send>() -> (Sender<T>, Receiver<T>)

Creates a oneshot channel. A value can be sent into this channel and then be asynchronously waited for.

Examples

Sending a value:

let (tx, rx) = catty::oneshot();
tx.send("Hello!");
assert_eq!(rx.await, Ok("Hello!"));

Dropping the sender:

let (tx, rx) = catty::oneshot::<u32>();
drop(tx);
assert_eq!(rx.await, Err(Disconnected));

Dropping the receiver:

let (tx, rx) = catty::oneshot::<&str>();
drop(rx);
assert_eq!(tx.send("Hello!"), Err("Hello!"));