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 {
- on_foo_handlers: Vec<Sender<Foo, &'static str>>
- }
- impl A {
- fn on_foo(&mut self) -> Stream<Foo, &'static str> {
- let (sender, receiver) = Stream::pair();
- self.on_foo_handlers.push(sender);
- receiver
- }
- fn listen(mut self) {
- loop {
- // be busy
- self.on_foo_handlers = self.on_foo_handlers.map_in_place(|s| {
- s.send(Foo).await().unwrap()
- });
- }
- }
- }
- fn main() {
- let mut a = A { on_foo_handlers: Vec::new() };
- a.on_foo().each(|foo| println!("{:?}", foo)).fire();
- a.listen();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement