Class ShareReplayOperator
Implements the ShareReplay operator. Mirrors rxjs's shareReplay().
public static class ShareReplayOperator
- Inheritance
-
System.ObjectShareReplayOperator
Methods
ShareReplay<T>(Observable<T>, int)
Multicasts source through an internal ReplaySubject<T>, so late
subscribers immediately receive the last bufferSize values (unbounded by default,
matching ReplaySubject<T>'s own default). Subscribes to the source only once (on the first
subscriber). Once the source completes, its buffered values keep replaying to every later subscriber
forever (the source is never resubscribed) -- matches rxjs's resetOnComplete: false default, and
is the whole reason to reach for shareReplay over share (e.g. caching a completed request).
If the source errors instead, the connector resets and a later subscriber gets a fresh
ReplaySubject<T> and a fresh subscription to the source (matches rxjs's
resetOnError: true default).
Deliberate deviation from rxjs: real rxjs's shareReplay() also defaults refCount: false --
even while the source is still live, it never unsubscribes when every subscriber leaves, only when the
source itself errors/completes. This port always disconnects once the subscriber count drops to zero
(the refCount: true mode) rather than leaking a live subscription forever with nobody listening;
there's no knob to opt into the leaky default.
public static Observable<T> ShareReplay<T>(this Observable<T> source, int bufferSize = null)
Parameters
sourceObservable<T>The source observable to multicast.
bufferSizeintThe maximum number of most-recent values to replay to each new subscriber. Unbounded by default.
Returns
- Observable<T>
A multicast, replaying observable that shares one subscription to
sourceamong all its subscribers.
Type Parameters
TThe element type of the source observable.