pub fn channel<T>() -> (Sender<T>, Receiver<T>)
Expand description

Create a new one-shot channel for sending single values across asynchronous tasks.

The function returns separate “send” and “receive” handles. The Sender handle is used by the producer to send the value. The Receiver handle is used by the consumer to receive the value.

Each handle can be used on separate tasks.

Examples

extern crate futures;
extern crate tokio;

use tokio::sync::oneshot;
use futures::Future;
use std::thread;

let (sender, receiver) = oneshot::channel::<i32>();

thread::spawn(|| {
    let future = receiver.map(|i| {
        println!("got: {:?}", i);
    });
    // ...
});

sender.send(3).unwrap();