a zip code crypto-currency system good for red ONLY

bufferTime.js 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { async } from '../scheduler/async';
  2. import { isScheduler } from '../util/isScheduler';
  3. import { bufferTime as higherOrder } from '../operators/bufferTime';
  4. /* tslint:enable:max-line-length */
  5. /**
  6. * Buffers the source Observable values for a specific time period.
  7. *
  8. * <span class="informal">Collects values from the past as an array, and emits
  9. * those arrays periodically in time.</span>
  10. *
  11. * <img src="./img/bufferTime.png" width="100%">
  12. *
  13. * Buffers values from the source for a specific time duration `bufferTimeSpan`.
  14. * Unless the optional argument `bufferCreationInterval` is given, it emits and
  15. * resets the buffer every `bufferTimeSpan` milliseconds. If
  16. * `bufferCreationInterval` is given, this operator opens the buffer every
  17. * `bufferCreationInterval` milliseconds and closes (emits and resets) the
  18. * buffer every `bufferTimeSpan` milliseconds. When the optional argument
  19. * `maxBufferSize` is specified, the buffer will be closed either after
  20. * `bufferTimeSpan` milliseconds or when it contains `maxBufferSize` elements.
  21. *
  22. * @example <caption>Every second, emit an array of the recent click events</caption>
  23. * var clicks = Rx.Observable.fromEvent(document, 'click');
  24. * var buffered = clicks.bufferTime(1000);
  25. * buffered.subscribe(x => console.log(x));
  26. *
  27. * @example <caption>Every 5 seconds, emit the click events from the next 2 seconds</caption>
  28. * var clicks = Rx.Observable.fromEvent(document, 'click');
  29. * var buffered = clicks.bufferTime(2000, 5000);
  30. * buffered.subscribe(x => console.log(x));
  31. *
  32. * @see {@link buffer}
  33. * @see {@link bufferCount}
  34. * @see {@link bufferToggle}
  35. * @see {@link bufferWhen}
  36. * @see {@link windowTime}
  37. *
  38. * @param {number} bufferTimeSpan The amount of time to fill each buffer array.
  39. * @param {number} [bufferCreationInterval] The interval at which to start new
  40. * buffers.
  41. * @param {number} [maxBufferSize] The maximum buffer size.
  42. * @param {Scheduler} [scheduler=async] The scheduler on which to schedule the
  43. * intervals that determine buffer boundaries.
  44. * @return {Observable<T[]>} An observable of arrays of buffered values.
  45. * @method bufferTime
  46. * @owner Observable
  47. */
  48. export function bufferTime(bufferTimeSpan) {
  49. let length = arguments.length;
  50. let scheduler = async;
  51. if (isScheduler(arguments[arguments.length - 1])) {
  52. scheduler = arguments[arguments.length - 1];
  53. length--;
  54. }
  55. let bufferCreationInterval = null;
  56. if (length >= 2) {
  57. bufferCreationInterval = arguments[1];
  58. }
  59. let maxBufferSize = Number.POSITIVE_INFINITY;
  60. if (length >= 3) {
  61. maxBufferSize = arguments[2];
  62. }
  63. return higherOrder(bufferTimeSpan, bufferCreationInterval, maxBufferSize, scheduler)(this);
  64. }
  65. //# sourceMappingURL=bufferTime.js.map