bufferWithTime - richardszalay/raix GitHub Wiki
ο»ΏEmits the values from a source sequence in groups on a time interval
function bufferWithTime(timeMs : uint, timeShiftMs : uint = 0,
scheduler : IScheduler = null) : IObservable.<Array>Values are emitted as arrays in groups colletected in intervals of timeMs. If the sequence finishes before the buffer is filled, the current buffer will be emitted.
If timeShiftMs is specified, only timeShiftMs milliseonds worth of the buffer will be discarded after being emitted. By default, the entire buffer is discarded between timeMs intervals.
The returned sequence completes when the source sequence completes
The returned sequence raises an error if the source sequence raises an error error.
xs = source
ys = output
c = count
timeMs timeMs
βββββββββΌββββββββ
0 1 2 β3 4
xs βoββoββoββΌoββoββ/
β β βββ€β ββββ€
β ββββββ€βββββββ€
βββββββββ€ β
ys βββββββββoββββββo
[0,1,c] [3,4]IObservable.<Array>
Observable.interval(500)
.bufferWithTime(1500)
.subscribe(
function(values : Array) : void
{
trace(values.join(", "));
});
// Trace output is:
// 0, 1, 2
// 3, 4, 5
// 6, 7, 8
// 9, 10, 11
// ...Observable.interval(500)
.bufferWithTime(1500, 1000)
.subscribe(
function(values : Array) : void
{
trace(values.join(", "));
});
// Trace output is:
// 0, 1, 2
// 2, 3, 4
// 4, 5, 6
// 6, 7, 8
// ...