Class BufferTimeOperator
The bufferTime operator.
public static class BufferTimeOperator
- Inheritance
-
System.ObjectBufferTimeOperator
Methods
BufferTime<T>(Observable<T>, TimeSpan, TimeSpan?, int?, IScheduler?)
Like BufferCount<T>(Observable<T>, int, int?), but buffers close on a fixed time period instead of a
value count. Mirrors rxjs's bufferTime. Implemented directly against source (the
same open-buffers-list algorithm as WindowTime<T>(Observable<T>, TimeSpan, TimeSpan?, int?, IScheduler?), but collecting into
List<T> buffers instead of emitting live windows) rather than composing
WindowTime + a per-window collector, to avoid a dependency on an unrelated, not-yet-existing operator.
public static Observable<IReadOnlyList<T>> BufferTime<T>(this Observable<T> source, TimeSpan bufferTimeSpan, TimeSpan? bufferCreationInterval = null, int? maxBufferSize = null, IScheduler? scheduler = null)
Parameters
sourceObservable<T>The source observable to buffer.
bufferTimeSpanTimeSpanHow long each buffer stays open before being emitted.
bufferCreationIntervalTimeSpan?How often a new buffer opens. Defaults to null (open a new buffer right after the previous one closes).
maxBufferSizeint?The maximum number of values a buffer may collect before closing early, regardless of
bufferTimeSpan. Defaults to unlimited.schedulerISchedulerThe scheduler to time buffers with; defaults to TaskPoolScheduler.
Returns
- Observable<IReadOnlyList<T>>
An observable of each completed (or trailing partial) buffer as an IReadOnlyList<T>.
Type Parameters
TThe type of the elements collected into each buffer.
Remarks
The first buffer opens eagerly at subscription time. When bufferCreationInterval is
null (the two-argument form), a new buffer opens immediately whenever the previous one
closes and is emitted after bufferTimeSpan elapses, producing non-overlapping buffers.
When bufferCreationInterval is given, new buffers instead open on their own independent
timer (starting immediately, then every bufferCreationInterval), each emitted
bufferTimeSpan after it opened — so multiple buffers can be collecting at once if
bufferCreationInterval is shorter than bufferTimeSpan. Independent of
either timer, a buffer also closes and emits as soon as it has collected maxBufferSize
values (a new one opens immediately in the non-overlapping, bufferCreationInterval-less form).
If source completes while one or more buffers are still open, those partial buffers are
emitted as-is, in the order they were opened, before completion is forwarded.