Exemple #1
0
 public static SubscribeFn <C> buffer <A, C>(
     IObservable <A> o, int size, IObservableQueue <A, C> queue
     ) =>
 obs => o.subscribe(
     val => {
     queue.addLast(val);
     if (queue.count > size)
     {
         queue.removeFirst();
     }
     obs.push(queue.collection);
 },
     obs.finish
     );
Exemple #2
0
 public static SubscribeFn <C> timeBuffer <A, C>(
     IObservable <A> o, Duration duration,
     IObservableQueue <Tpl <A, float>, C> queue,
     TimeScale timeScale
     )
 {
     return(obs => o.subscribe(val => {
         queue.addLast(F.t(val, timeScale.now()));
         var lastTime = queue.last._2;
         if (queue.first._2 + duration.seconds <= lastTime)
         {
             // Remove items which are too old.
             while (queue.first._2 + duration.seconds < lastTime)
             {
                 queue.removeFirst();
             }
             obs.push(queue.collection);
         }
     }));
 }