Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(collections)]
- extern crate eventual;
- use eventual::*;
- #[derive(Debug)]
- struct Foo;
- struct A<'a> {
- on_foo_handlers: Vec<Sender<(&'a mut A<'a>, &'a Foo), &'static str>>
- }
- impl<'a> A<'a> {
- fn on_foo(&mut self) -> Stream<(&'a mut A<'a>, &'a Foo), &'static str> {
- let (sender, receiver) = Stream::pair();
- self.on_foo_handlers.push(sender);
- receiver
- }
- fn bar(&mut self) {
- // something
- }
- fn listen(mut self) {
- loop {
- // be busy
- self.on_foo_handlers = self.on_foo_handlers.map_in_place(|s| {
- s.send((&mut self, &Foo)).await().unwrap()
- });
- }
- }
- }
- fn main() {
- let mut a = A { on_foo_handlers: Vec::new() };
- a.on_foo().each(|(s, foo)| println!("{:?}, {:?}", s.bar(), foo)).fire();
- a.listen();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement