Function channel

fn channel<T>() -> (Sender<T>, Receiver<T>)

Creates a new oneshot channel, returning the sender/receiver halves.

Examples

#![feature(oneshot_channel)]
use std::sync::oneshot;
use std::thread;

let (sender, receiver) = oneshot::channel();

// Spawn off an expensive computation.
thread::spawn(move || {
#   fn expensive_computation() -> i32 { 42 }
    sender.send(expensive_computation()).unwrap();
    // `sender` is consumed by `send`, so we cannot use it anymore.
});

# fn do_other_work() -> i32 { 42 }
do_other_work();

// Let's see what that answer was...
println!("{:?}", receiver.recv().unwrap());
// `receiver` is consumed by `recv`, so we cannot use it anymore.