Last active
September 10, 2016 08:21
-
-
Save Troxid/6fb396b2b126fc806076f00941f4ece9 to your computer and use it in GitHub Desktop.
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
| struct Server{ | |
| out_buffer: Vec<String>, | |
| in_buffer: Vec<String>, | |
| ... | |
| } | |
| impl Server { | |
| fn send(&mut self, msg: String){ | |
| self.in_buffer.push(msg); | |
| } | |
| fn recv(&mut self) -> Option<String>{ | |
| self.out_buffer.pop(); | |
| } | |
| fn run(&mut self){ | |
| thread::spawn(move ||{ | |
| loop{ | |
| // mutate out_buffer | |
| // mutate in_buffer | |
| // mutate other fields | |
| } | |
| }); | |
| } | |
| } | |
| fn main(){ | |
| let s = Server::new(); | |
| s.run() //non blocking | |
| s.send("hello".into()); | |
| let msg = s.recv().unwrup(); | |
| println!("{:?}", msg); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment