Last active
December 22, 2015 17:19
-
-
Save olsonjeffery/6505233 to your computer and use it in GitHub Desktop.
time for bed, old man!
This file contains hidden or 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
use std::rt::comm; | |
use std::rt::io::timer::Timer; | |
use std::cell::Cell; | |
trait SleepyPort<T: Send> { | |
fn recv_timeout(self, msecs: u64) -> Option<T>; | |
} | |
impl<T: Send> SleepyPort<T> for comm::PortOne<T> { | |
fn recv_timeout(self, msecs: u64) -> Option<T> { | |
if self.peek() { return Some(self.recv()); } | |
match Timer::new() { | |
Some(ref mut t) => t.sleep(msecs), | |
None => {} // this probably raised a condition... | |
} | |
match self.peek() { | |
true => Some(self.recv()), | |
_ => None | |
} | |
} | |
} | |
fn main() { | |
println("bleh"); | |
let (p, c) = comm::oneshot(); | |
let c_cell = Cell::new(c); | |
do spawn { let c = c_cell.take(); c.send("f") } | |
let r = p.recv_timeout(2000).unwrap(); | |
println(r); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment