Table of Contents

Class ReplaySubject<T>

Namespace
RxSharp.Subjects
Assembly
RxSharp.dll

A Subject<T> that buffers emitted values and replays them to new subscribers before they start receiving live values. Mirrors rxjs's ReplaySubject.

public sealed class ReplaySubject<T> : Subject<T>, IObserver<T>, IDisposable

Type Parameters

T

The type of values pushed through the subject.

Inheritance
System.Object
ReplaySubject<T>
Implements
IObserver<T>
IDisposable
Inherited Members

Constructors

ReplaySubject(int, TimeSpan?, Func<DateTimeOffset>?)

Initializes a new instance of the ReplaySubject<T> class.

public ReplaySubject(int bufferSize = null, TimeSpan? windowTime = null, Func<DateTimeOffset>? clock = null)

Parameters

bufferSize int

The maximum number of most-recent values kept for replay. Defaults to int.MaxValue, i.e. effectively unbounded — every value ever pushed is replayed to new subscribers unless trimmed by windowTime.

windowTime TimeSpan?

The maximum age of a buffered value, relative to clock. Values older than this are dropped from the buffer. Defaults to null, meaning no age-based trimming — only bufferSize bounds the buffer.

clock Func<DateTimeOffset>?

Supplies the current time used to timestamp buffered values and evaluate windowTime. Defaults to DateTimeOffset.UtcNow.

Methods

Dispose()

Clears the replay buffer in addition to the base Subject<T> disposal behavior.

public override void Dispose()

OnNext(T)

Buffers value (subject to trimming by buffer size/window time) and then pushes it to every observer currently subscribed. The stopped/disposed check happens before buffering, not just before forwarding — a value nexted after OnCompleted()/OnError(Exception) is neither forwarded nor buffered, so it can never be wrongly replayed to a subscriber that arrives afterward.

public override void OnNext(T value)

Parameters

value T

The value to buffer and push.

Subscribe(IObserver<T>)

Replays every currently buffered value to observer (oldest first), trimming the buffer first, and then subscribes it to the underlying Subject<T> for subsequent live values exactly as Subscribe(IObserver<T>) would.

public override IDisposable Subscribe(IObserver<T> observer)

Parameters

observer IObserver<T>

The observer to replay buffered values to and then subscribe.

Returns

IDisposable

A disposable that unsubscribes the observer from future (non-replayed) notifications.