Table of Contents

Class BufferTimeOperator

Namespace
RxSharp.Operators
Assembly
RxSharp.dll

The bufferTime operator.

public static class BufferTimeOperator
Inheritance
System.Object
BufferTimeOperator

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

source Observable<T>

The source observable to buffer.

bufferTimeSpan TimeSpan

How long each buffer stays open before being emitted.

bufferCreationInterval TimeSpan?

How often a new buffer opens. Defaults to null (open a new buffer right after the previous one closes).

maxBufferSize int?

The maximum number of values a buffer may collect before closing early, regardless of bufferTimeSpan. Defaults to unlimited.

scheduler IScheduler

The 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

T

The 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.