forked from richardszalay/raix
-
Notifications
You must be signed in to change notification settings - Fork 0
windowWithTime
richardszalay edited this page May 20, 2011
·
3 revisions
Emits the values from a source sequence in groups on a time interval
function bufferWithTime(timeMs : uint, timeShiftMs : uint = 0,
scheduler : IScheduler = null) : IObservable
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
// ...