pub fn channel<T>() -> (Sender<T>, Receiver<T>)
Expand description
Creates a new one-shot channel for sending values across asynchronous tasks.
This function is similar to Rust’s channel constructor found in the standard library.
Two halves are returned, the first of which is a Sender
handle, used to
signal the end of a computation and provide its value. The second half is a
Receiver
which implements the Future
trait, resolving to the value that
was given to the Sender
handle.
Each half can be separately owned and sent across tasks.
§Examples
extern crate futures;
extern crate futures_channel;
use std::thread;
use futures_channel::oneshot;
use futures::*;
fn main() {
let (p, c) = oneshot::channel::<i32>();
thread::spawn(|| {
let future = c.map(|i| {
println!("got: {}", i);
});
// ...
});
p.send(3).unwrap();
}