Advertisement
Guest User

Untitled

a guest
May 24th, 2015
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #![feature(collections)]
  2. extern crate eventual;
  3.  
  4. use eventual::*;
  5.  
  6. #[derive(Debug)]
  7. struct Foo;
  8.  
  9. struct A {
  10. on_foo_handlers: Vec<Sender<Foo, &'static str>>
  11. }
  12.  
  13. impl A {
  14. fn on_foo(&mut self) -> Stream<Foo, &'static str> {
  15. let (sender, receiver) = Stream::pair();
  16. self.on_foo_handlers.push(sender);
  17. receiver
  18. }
  19.  
  20. fn listen(mut self) {
  21. loop {
  22. // be busy
  23. self.on_foo_handlers = self.on_foo_handlers.map_in_place(|s| {
  24. s.send(Foo).await().unwrap()
  25. });
  26. }
  27. }
  28. }
  29.  
  30. fn main() {
  31. let mut a = A { on_foo_handlers: Vec::new() };
  32. a.on_foo().each(|foo| println!("{:?}", foo)).fire();
  33. a.listen();
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement