You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.8 KiB
67 lines
2.8 KiB
"use strict"; |
|
var async_1 = require('../scheduler/async'); |
|
var isScheduler_1 = require('../util/isScheduler'); |
|
var bufferTime_1 = require('../operators/bufferTime'); |
|
/* tslint:enable:max-line-length */ |
|
/** |
|
* Buffers the source Observable values for a specific time period. |
|
* |
|
* <span class="informal">Collects values from the past as an array, and emits |
|
* those arrays periodically in time.</span> |
|
* |
|
* <img src="./img/bufferTime.png" width="100%"> |
|
* |
|
* Buffers values from the source for a specific time duration `bufferTimeSpan`. |
|
* Unless the optional argument `bufferCreationInterval` is given, it emits and |
|
* resets the buffer every `bufferTimeSpan` milliseconds. If |
|
* `bufferCreationInterval` is given, this operator opens the buffer every |
|
* `bufferCreationInterval` milliseconds and closes (emits and resets) the |
|
* buffer every `bufferTimeSpan` milliseconds. When the optional argument |
|
* `maxBufferSize` is specified, the buffer will be closed either after |
|
* `bufferTimeSpan` milliseconds or when it contains `maxBufferSize` elements. |
|
* |
|
* @example <caption>Every second, emit an array of the recent click events</caption> |
|
* var clicks = Rx.Observable.fromEvent(document, 'click'); |
|
* var buffered = clicks.bufferTime(1000); |
|
* buffered.subscribe(x => console.log(x)); |
|
* |
|
* @example <caption>Every 5 seconds, emit the click events from the next 2 seconds</caption> |
|
* var clicks = Rx.Observable.fromEvent(document, 'click'); |
|
* var buffered = clicks.bufferTime(2000, 5000); |
|
* buffered.subscribe(x => console.log(x)); |
|
* |
|
* @see {@link buffer} |
|
* @see {@link bufferCount} |
|
* @see {@link bufferToggle} |
|
* @see {@link bufferWhen} |
|
* @see {@link windowTime} |
|
* |
|
* @param {number} bufferTimeSpan The amount of time to fill each buffer array. |
|
* @param {number} [bufferCreationInterval] The interval at which to start new |
|
* buffers. |
|
* @param {number} [maxBufferSize] The maximum buffer size. |
|
* @param {Scheduler} [scheduler=async] The scheduler on which to schedule the |
|
* intervals that determine buffer boundaries. |
|
* @return {Observable<T[]>} An observable of arrays of buffered values. |
|
* @method bufferTime |
|
* @owner Observable |
|
*/ |
|
function bufferTime(bufferTimeSpan) { |
|
var length = arguments.length; |
|
var scheduler = async_1.async; |
|
if (isScheduler_1.isScheduler(arguments[arguments.length - 1])) { |
|
scheduler = arguments[arguments.length - 1]; |
|
length--; |
|
} |
|
var bufferCreationInterval = null; |
|
if (length >= 2) { |
|
bufferCreationInterval = arguments[1]; |
|
} |
|
var maxBufferSize = Number.POSITIVE_INFINITY; |
|
if (length >= 3) { |
|
maxBufferSize = arguments[2]; |
|
} |
|
return bufferTime_1.bufferTime(bufferTimeSpan, bufferCreationInterval, maxBufferSize, scheduler)(this); |
|
} |
|
exports.bufferTime = bufferTime; |
|
//# sourceMappingURL=bufferTime.js.map
|