Created
March 26, 2014 05:37
-
-
Save gavinb/9777418 to your computer and use it in GitHub Desktop.
Trying to share channels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate native; | |
use std::comm::{Sender, Receiver, TryRecvResult, Data, channel}; | |
struct Master<'a> { | |
chan_wc_to_engine: Sender<uint>, | |
chan_wc_from_engine: Receiver<uint>, | |
chan_engine_to_wc: Sender<uint>, | |
chan_engine_from_wc: Receiver<uint>, | |
} | |
impl<'a> Master<'a> { | |
fn new() -> Master<'a> { | |
let (chan_wc_to_engine, chan_engine_from_wc) = channel(); | |
let (chan_engine_to_wc, chan_wc_from_engine) = channel(); | |
let master = Master{ chan_wc_to_engine: chan_wc_to_engine, | |
chan_wc_from_engine: chan_wc_from_engine, | |
chan_engine_to_wc: chan_engine_to_wc, | |
chan_engine_from_wc: chan_engine_from_wc, | |
}; | |
master | |
} | |
fn start_engine(&self) { | |
println!("start_engine"); | |
native::task::spawn( proc() { | |
println!("process"); | |
self.chan_engine_to_wc.send(42); // *** | |
println!("done"); | |
}); | |
} | |
fn listen(&self) { | |
println!("listen"); | |
let indata = self.chan_wc_from_engine.recv(); | |
println!("indata = {}", indata); | |
} | |
} | |
fn main() { | |
let m = Master::new(); | |
m.start_engine(); | |
m.listen(); | |
println!("fin"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This fails to compile with the error: