Guest User

Untitled

a guest
May 27th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. pub struct BufferInterval<T, S, I>
  2. where
  3. T: Stream<Item = I>,
  4. S: Store<Item = I>,
  5. I: Clone,
  6. {
  7. interval: Interval,
  8. rx: T,
  9. store: S,
  10. }
  11.  
  12. impl<T, S, I> Stream for BufferInterval<T, S, I>
  13. where
  14. T: Stream<Item = I>,
  15. S: Store<Item = I>,
  16. I: Clone,
  17. {
  18. type Item = S;
  19. type Error = Error;
  20.  
  21. fn poll(&mut self) -> Result<Async<Option<Self::Item>>> {
  22. loop {
  23. match self.interval.poll()? {
  24. Async::Ready(Some(_inst)) => {
  25. let store = self.store.trancate();
  26. return Ok(Async::Ready(Some(store)));
  27. }
  28. Async::Ready(None) => {
  29. unreachable!();
  30. }
  31. Async::NotReady => {
  32. trace!("not until to trancate");
  33. }
  34. };
  35.  
  36. match self.rx.poll()? {
  37. Async::Ready(Some(val)) => self.store.store(val),
  38. Async::NotReady => return Ok(Async::NotReady),
  39. Async::Ready(None) => return Ok(Async::Ready(None)),
  40. };
  41. }
  42. }
  43. }
Add Comment
Please, Sign In to add comment