Function futures::channel::oneshot::channel [−][src]
pub fn channel<T>() -> (Sender<T>, Receiver<T>)
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
use futures::channel::oneshot; use futures::prelude::*; use std::thread; fn main() { let (sender, receiver) = oneshot::channel::<i32>(); thread::spawn(|| { let future = receiver.map(|i| { println!("got: {:?}", i); }); // ... }); sender.send(3).unwrap(); }