timeInterval.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { Subscriber } from '../Subscriber';
  2. import { async } from '../scheduler/async';
  3. export function timeInterval(scheduler = async) {
  4. return (source) => source.lift(new TimeIntervalOperator(scheduler));
  5. }
  6. export class TimeInterval {
  7. constructor(value, interval) {
  8. this.value = value;
  9. this.interval = interval;
  10. }
  11. }
  12. ;
  13. class TimeIntervalOperator {
  14. constructor(scheduler) {
  15. this.scheduler = scheduler;
  16. }
  17. call(observer, source) {
  18. return source.subscribe(new TimeIntervalSubscriber(observer, this.scheduler));
  19. }
  20. }
  21. /**
  22. * We need this JSDoc comment for affecting ESDoc.
  23. * @ignore
  24. * @extends {Ignored}
  25. */
  26. class TimeIntervalSubscriber extends Subscriber {
  27. constructor(destination, scheduler) {
  28. super(destination);
  29. this.scheduler = scheduler;
  30. this.lastTime = 0;
  31. this.lastTime = scheduler.now();
  32. }
  33. _next(value) {
  34. let now = this.scheduler.now();
  35. let span = now - this.lastTime;
  36. this.lastTime = now;
  37. this.destination.next(new TimeInterval(value, span));
  38. }
  39. }
  40. //# sourceMappingURL=timeInterval.js.map