Guest User

Untitled

a guest
Jul 17th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. extern crate futures; // 0.1.21
  2.  
  3. use futures::Future;
  4. use futures::Stream;
  5. use futures::Poll;
  6. use futures::sync::mpsc::{unbounded, UnboundedSender, UnboundedReceiver};
  7.  
  8.  
  9. struct A {
  10. tx: UnboundedSender<i32>,
  11. }
  12.  
  13. struct B {
  14. rx: UnboundedReceiver<i32>,
  15. }
  16.  
  17. impl Future for B {
  18. type Item = i32;
  19. type Error = ();
  20.  
  21. fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
  22. self.rx.poll().map(|a| a.map(|o| o.unwrap()))
  23. }
  24. }
  25.  
  26. fn main() {
  27. let (tx, rx) = unbounded();
  28. let a = A { tx };
  29. let mut b = B { rx };
  30.  
  31. b.poll();
  32. }
Add Comment
Please, Sign In to add comment