Table of Contents

Class Observable

Namespace
RxSharp
Assembly
RxSharp.dll

Creation functions for Observable<T>. Mirrors rxjs's observable/ creation functions.

public static class Observable
Inheritance
System.Object
Observable

Methods

BindCallback(Action<Action>)

Wraps a 0-input-argument callback-style function (whose last parameter is a plain, no-error callback) into a function that returns an Observable<T>. Mirrors rxjs's bindCallback: the wrapped function is invoked at most once per call to the returned function -- the first subscriber to the resulting observable triggers the call, and every subscriber (including ones that subscribe later, after the callback already fired) shares and replays the same cached result, exactly like rxjs's internal AsyncSubject-backed caching. See the BindCallback<TResult> overload's remarks for the deliberate deviations from rxjs's literal behavior (no scheduler parameter, no resultSelector parameter, single-result-value callbacks only).

public static Func<Observable<Unit>> BindCallback(Action<Action> func)

Parameters

func Action<Action>

The callback-style function to wrap. Its only parameter is the callback to invoke once the underlying work completes.

Returns

Func<Observable<Unit>>

A function that, when called, returns an Observable<T> emitting Default then completing once the callback fires.

BindCallback<TResult>(Action<Action<TResult>>)

Wraps a 0-input-argument callback-style function (whose last parameter is a plain callback receiving a single result value) into a function that returns an Observable<T>. Mirrors rxjs's bindCallback.

public static Func<Observable<TResult>> BindCallback<TResult>(Action<Action<TResult>> func)

Parameters

func Action<Action<TResult>>

The callback-style function to wrap.

Returns

Func<Observable<TResult>>

A function that, when called, returns an Observable<T> emitting the callback's result then completing.

Type Parameters

TResult

The type of the single value the callback is invoked with.

Remarks

Deliberate deviations from rxjs's literal bindCallback:

  • No scheduler parameter: rxjs composes an optional scheduler via its own subscribeOn/observeOn operators, which RxSharp does not have yet. The wrapped function is always invoked synchronously, on the subscribing thread, at first-subscribe time.
  • No resultSelector parameter: since the returned function already produces a full Observable<T>, a caller gets the same effect (and more idiomatically) via .Map(selector) on the result.
  • Only a single result value is supported (rxjs packs multiple callback arguments into an array). C# delegates aren't variadic; a callback-style API with several logically-related result values should bundle them into a tuple or record before calling back.
  • No JS-style dynamic this rebinding (rxjs's .apply/.call tests): the wrapped delegate already captures whatever state/closure the caller bound it to.

BindCallback<T1>(Action<T1, Action>)

Overload of BindCallback(Action<Action>) for a 1-input-argument callback-style function.

public static Func<T1, Observable<Unit>> BindCallback<T1>(Action<T1, Action> func)

Parameters

func Action<T1, Action>

The callback-style function to wrap.

Returns

Func<T1, Observable<Unit>>

A function that, given the input argument, returns an Observable<T> emitting Default then completing once the callback fires.

Type Parameters

T1

The type of the function's first argument.

BindCallback<T1, TResult>(Action<T1, Action<TResult>>)

Overload of BindCallback<TResult>(Action<Action<TResult>>) for a 1-input-argument callback-style function. See that overload's remarks for the deliberate deviations from rxjs.

public static Func<T1, Observable<TResult>> BindCallback<T1, TResult>(Action<T1, Action<TResult>> func)

Parameters

func Action<T1, Action<TResult>>

The callback-style function to wrap.

Returns

Func<T1, Observable<TResult>>

A function that, given the input argument, returns an Observable<T> emitting the callback's result then completing.

Type Parameters

T1

The type of the function's first argument.

TResult

The type of the single value the callback is invoked with.

BindCallback<T1, T2>(Action<T1, T2, Action>)

Overload of BindCallback(Action<Action>) for a 2-input-argument callback-style function.

public static Func<T1, T2, Observable<Unit>> BindCallback<T1, T2>(Action<T1, T2, Action> func)

Parameters

func Action<T1, T2, Action>

The callback-style function to wrap.

Returns

Func<T1, T2, Observable<Unit>>

A function that, given the input arguments, returns an Observable<T> emitting Default then completing once the callback fires.

Type Parameters

T1

The type of the function's first argument.

T2

The type of the function's second argument.

BindCallback<T1, T2, TResult>(Action<T1, T2, Action<TResult>>)

Overload of BindCallback<TResult>(Action<Action<TResult>>) for a 2-input-argument callback-style function. See that overload's remarks for the deliberate deviations from rxjs.

public static Func<T1, T2, Observable<TResult>> BindCallback<T1, T2, TResult>(Action<T1, T2, Action<TResult>> func)

Parameters

func Action<T1, T2, Action<TResult>>

The callback-style function to wrap.

Returns

Func<T1, T2, Observable<TResult>>

A function that, given the input arguments, returns an Observable<T> emitting the callback's result then completing.

Type Parameters

T1

The type of the function's first argument.

T2

The type of the function's second argument.

TResult

The type of the single value the callback is invoked with.

BindCallback<T1, T2, T3>(Action<T1, T2, T3, Action>)

Overload of BindCallback(Action<Action>) for a 3-input-argument callback-style function.

public static Func<T1, T2, T3, Observable<Unit>> BindCallback<T1, T2, T3>(Action<T1, T2, T3, Action> func)

Parameters

func Action<T1, T2, T3, Action>

The callback-style function to wrap.

Returns

Func<T1, T2, T3, Observable<Unit>>

A function that, given the input arguments, returns an Observable<T> emitting Default then completing once the callback fires.

Type Parameters

T1

The type of the function's first argument.

T2

The type of the function's second argument.

T3

The type of the function's third argument.

BindCallback<T1, T2, T3, TResult>(Action<T1, T2, T3, Action<TResult>>)

Overload of BindCallback<TResult>(Action<Action<TResult>>) for a 3-input-argument callback-style function. See that overload's remarks for the deliberate deviations from rxjs.

public static Func<T1, T2, T3, Observable<TResult>> BindCallback<T1, T2, T3, TResult>(Action<T1, T2, T3, Action<TResult>> func)

Parameters

func Action<T1, T2, T3, Action<TResult>>

The callback-style function to wrap.

Returns

Func<T1, T2, T3, Observable<TResult>>

A function that, given the input arguments, returns an Observable<T> emitting the callback's result then completing.

Type Parameters

T1

The type of the function's first argument.

T2

The type of the function's second argument.

T3

The type of the function's third argument.

TResult

The type of the single value the callback is invoked with.

BindNodeCallback(Action<Action<Exception?>>)

Wraps a 0-input-argument, Node.js-convention callback-style function (whose last parameter is a callback receiving an error-or-null first, with no success value) into a function that returns an Observable<T>. Mirrors rxjs's bindNodeCallback. See the BindNodeCallback<TResult> overload's remarks for the deliberate deviations from rxjs's literal behavior.

public static Func<Observable<Unit>> BindNodeCallback(Action<Action<Exception?>> func)

Parameters

func Action<Action<Exception?>>

The callback-style function to wrap. Its only parameter is the callback to invoke once the underlying work completes, with null for no error.

Returns

Func<Observable<Unit>>

A function that, when called, returns an Observable<T> emitting Default then completing once the callback fires without an error, or erroring if it fires with one.

BindNodeCallback<TResult>(Action<Action<Exception?, TResult>>)

Wraps a 0-input-argument, Node.js-convention callback-style function (whose last parameter is a callback receiving an error-or-null first, then a single success value) into a function that returns an Observable<T>. Mirrors rxjs's bindNodeCallback.

public static Func<Observable<TResult>> BindNodeCallback<TResult>(Action<Action<Exception?, TResult>> func)

Parameters

func Action<Action<Exception?, TResult>>

The callback-style function to wrap.

Returns

Func<Observable<TResult>>

A function that, when called, returns an Observable<T> emitting the callback's success value then completing, or erroring if the callback fires with a non-null error.

Type Parameters

TResult

The type of the success value the callback is invoked with.

Remarks

Deliberate deviations from rxjs's literal bindNodeCallback, in addition to the ones already listed on BindCallback<TResult>(Action<Action<TResult>>) (no scheduler parameter, no resultSelector parameter, single-result-value callbacks only, no JS-style dynamic this rebinding):

  • The Node.js "first callback argument is the error, or a loosely-falsy value like null/undefined for no error" convention is mapped to a strongly-typed Exception? first parameter: null means no error, any non-null Exception is forwarded via the resulting observable's OnError. This is the cleanest idiomatic C# mapping -- there is no equivalent to JS's untyped falsy-check for an arbitrary error value.

BindNodeCallback<T1>(Action<T1, Action<Exception?>>)

Overload of BindNodeCallback(Action<Action<Exception>>) for a 1-input-argument callback-style function.

public static Func<T1, Observable<Unit>> BindNodeCallback<T1>(Action<T1, Action<Exception?>> func)

Parameters

func Action<T1, Action<Exception?>>

The callback-style function to wrap.

Returns

Func<T1, Observable<Unit>>

A function that, given the input argument, returns an Observable<T> emitting Default then completing once the callback fires without an error, or erroring if it fires with one.

Type Parameters

T1

The type of the function's first argument.

BindNodeCallback<T1, TResult>(Action<T1, Action<Exception?, TResult>>)

Overload of BindNodeCallback<TResult>(Action<Action<Exception, TResult>>) for a 1-input-argument callback-style function. See that overload's remarks for the deliberate deviations from rxjs.

public static Func<T1, Observable<TResult>> BindNodeCallback<T1, TResult>(Action<T1, Action<Exception?, TResult>> func)

Parameters

func Action<T1, Action<Exception?, TResult>>

The callback-style function to wrap.

Returns

Func<T1, Observable<TResult>>

A function that, given the input argument, returns an Observable<T> emitting the callback's success value then completing, or erroring if the callback fires with a non-null error.

Type Parameters

T1

The type of the function's first argument.

TResult

The type of the success value the callback is invoked with.

BindNodeCallback<T1, T2>(Action<T1, T2, Action<Exception?>>)

Overload of BindNodeCallback(Action<Action<Exception>>) for a 2-input-argument callback-style function.

public static Func<T1, T2, Observable<Unit>> BindNodeCallback<T1, T2>(Action<T1, T2, Action<Exception?>> func)

Parameters

func Action<T1, T2, Action<Exception?>>

The callback-style function to wrap.

Returns

Func<T1, T2, Observable<Unit>>

A function that, given the input arguments, returns an Observable<T> emitting Default then completing once the callback fires without an error, or erroring if it fires with one.

Type Parameters

T1

The type of the function's first argument.

T2

The type of the function's second argument.

BindNodeCallback<T1, T2, TResult>(Action<T1, T2, Action<Exception?, TResult>>)

Overload of BindNodeCallback<TResult>(Action<Action<Exception, TResult>>) for a 2-input-argument callback-style function. See that overload's remarks for the deliberate deviations from rxjs.

public static Func<T1, T2, Observable<TResult>> BindNodeCallback<T1, T2, TResult>(Action<T1, T2, Action<Exception?, TResult>> func)

Parameters

func Action<T1, T2, Action<Exception?, TResult>>

The callback-style function to wrap.

Returns

Func<T1, T2, Observable<TResult>>

A function that, given the input arguments, returns an Observable<T> emitting the callback's success value then completing, or erroring if the callback fires with a non-null error.

Type Parameters

T1

The type of the function's first argument.

T2

The type of the function's second argument.

TResult

The type of the success value the callback is invoked with.

BindNodeCallback<T1, T2, T3>(Action<T1, T2, T3, Action<Exception?>>)

Overload of BindNodeCallback(Action<Action<Exception>>) for a 3-input-argument callback-style function.

public static Func<T1, T2, T3, Observable<Unit>> BindNodeCallback<T1, T2, T3>(Action<T1, T2, T3, Action<Exception?>> func)

Parameters

func Action<T1, T2, T3, Action<Exception?>>

The callback-style function to wrap.

Returns

Func<T1, T2, T3, Observable<Unit>>

A function that, given the input arguments, returns an Observable<T> emitting Default then completing once the callback fires without an error, or erroring if it fires with one.

Type Parameters

T1

The type of the function's first argument.

T2

The type of the function's second argument.

T3

The type of the function's third argument.

BindNodeCallback<T1, T2, T3, TResult>(Action<T1, T2, T3, Action<Exception?, TResult>>)

Overload of BindNodeCallback<TResult>(Action<Action<Exception, TResult>>) for a 3-input-argument callback-style function. See that overload's remarks for the deliberate deviations from rxjs.

public static Func<T1, T2, T3, Observable<TResult>> BindNodeCallback<T1, T2, T3, TResult>(Action<T1, T2, T3, Action<Exception?, TResult>> func)

Parameters

func Action<T1, T2, T3, Action<Exception?, TResult>>

The callback-style function to wrap.

Returns

Func<T1, T2, T3, Observable<TResult>>

A function that, given the input arguments, returns an Observable<T> emitting the callback's success value then completing, or erroring if the callback fires with a non-null error.

Type Parameters

T1

The type of the function's first argument.

T2

The type of the function's second argument.

T3

The type of the function's third argument.

TResult

The type of the success value the callback is invoked with.

CombineLatest<T>(params Observable<T>[])

Emits a list of every source's latest value whenever any source emits, once all sources have emitted at least once. Same-type-only, see Zip<T>(params Observable<T>[]).

public static Observable<IReadOnlyList<T>> CombineLatest<T>(params Observable<T>[] sources)

Parameters

sources Observable<T>[]

The sources to combine.

Returns

Observable<IReadOnlyList<T>>

An observable that emits a snapshot list of the latest values, updated on every subsequent emission once every source has emitted at least once.

Type Parameters

T

The element type shared by every source.

Remarks

Completes only once every source has completed, matching rxjs's own combineLatest exactly (verified against the 7.8.2 tag's combineLatestInit, which just decrements an active counter on each source's completion and completes the result once it reaches zero — no special case for a source that completes without ever emitting). This means if a source completes without a value while another source is still active, the result does not complete early: it keeps waiting on the still-active source, even though it can now never emit (since it can never have "all sources' latest value"). This deliberately differs from ForkJoin<T>(params Observable<T>[]), which DOES complete eagerly the moment any source completes without a value — don't unify the two, they have genuinely different documented/tested behavior in rxjs itself.

Concat<T>(params Observable<T>[])

Creates an Observable<T> that subscribes to each of sources one at a time, in order, moving to the next only once the previous one completes.

public static Observable<T> Concat<T>(params Observable<T>[] sources)

Parameters

sources Observable<T>[]

The sources to subscribe to sequentially.

Returns

Observable<T>

An observable that emits every source's values in sequence, completing after the last source completes.

Type Parameters

T

The type of the emitted values.

Defer<T>(Func<Observable<T>>)

Creates an Observable<T> that calls factory to produce a fresh source for each new subscriber, rather than sharing one source across subscribers.

public static Observable<T> Defer<T>(Func<Observable<T>> factory)

Parameters

factory Func<Observable<T>>

Invoked once per subscription to produce the source observable.

Returns

Observable<T>

An observable that defers creation of its source until subscribe time.

Type Parameters

T

The type of the emitted values.

Empty<T>()

Creates an Observable<T> that completes immediately, without ever emitting a value.

public static Observable<T> Empty<T>()

Returns

Observable<T>

An observable that completes immediately.

Type Parameters

T

The (unused) element type, needed only so the result can be composed with other Observable<T> sources of the same type.

ForkJoin<T>(params Observable<T>[])

Waits for every source to complete, then emits a list of each source's last value — but only if every source emitted at least one value. Same-type-only, see Zip<T>(params Observable<T>[]).

public static Observable<IReadOnlyList<T>> ForkJoin<T>(params Observable<T>[] sources)

Parameters

sources Observable<T>[]

The sources to wait on.

Returns

Observable<IReadOnlyList<T>>

An observable that emits one list of final values once every source has completed, or completes immediately without emitting if any source completed without a value.

Type Parameters

T

The element type shared by every source.

FromEvent<TEventArgs>(Action<EventHandler<TEventArgs>>, Action<EventHandler<TEventArgs>>)

The common case of FromEvent<TDelegate, TEventArgs>(Action<TDelegate>, Action<TDelegate>, Func<Action<TEventArgs>, TDelegate>) for standard EventHandler<TEventArgs>-shaped .NET events.

public static Observable<TEventArgs> FromEvent<TEventArgs>(Action<EventHandler<TEventArgs>> addHandler, Action<EventHandler<TEventArgs>> removeHandler)

Parameters

addHandler Action<EventHandler<TEventArgs>>

Called once, at subscribe time, with the handler to add to the event.

removeHandler Action<EventHandler<TEventArgs>>

Called on unsubscribe, with the same handler, to remove it from the event.

Returns

Observable<TEventArgs>

An observable that emits each event's TEventArgs payload as it is raised.

Type Parameters

TEventArgs

The type of the event's payload, forwarded as each emitted value.

FromEvent<TDelegate, TEventArgs>(Action<TDelegate>, Action<TDelegate>, Func<Action<TEventArgs>, TDelegate>)

Wraps a .NET event (add/remove handler pair) as an Observable<T>. Mirrors rxjs's fromEvent and doubles as the C# analogue of Puppeteer's own fromEmitterEvent helper — .NET events are a fundamentally different shape from JS EventEmitters/DOM targets, so rather than port rxjs's many duck-typed overloads, this follows the established Rx.NET FromEvent idiom.

public static Observable<TEventArgs> FromEvent<TDelegate, TEventArgs>(Action<TDelegate> addHandler, Action<TDelegate> removeHandler, Func<Action<TEventArgs>, TDelegate> conversion)

Parameters

addHandler Action<TDelegate>

Called once, at subscribe time, with the handler to add to the event.

removeHandler Action<TDelegate>

Called on unsubscribe, with the same handler, to remove it from the event.

conversion Func<Action<TEventArgs>, TDelegate>

Converts an Action<TEventArgs> callback into the event's actual delegate shape.

Returns

Observable<TEventArgs>

An observable that emits each event payload as it is raised. Never completes on its own; unsubscribing removes the underlying event handler.

Type Parameters

TDelegate

The delegate type of the event handler (e.g. a custom event delegate type).

TEventArgs

The type of the event's payload, forwarded as each emitted value.

From<T>(IEnumerable<T>)

Creates an Observable<T> that synchronously emits every item of values, in enumeration order, then completes.

public static Observable<T> From<T>(IEnumerable<T> values)

Parameters

values IEnumerable<T>

The sequence to emit values from.

Returns

Observable<T>

An observable that emits every item of values, then completes.

Type Parameters

T

The type of the emitted values.

From<T>(Task<T>)

Creates an Observable<T> that emits the result of task and completes, or errors if the task faults or is cancelled. Continuation runs on the default task scheduler, not synchronously on the subscribing thread.

public static Observable<T> From<T>(Task<T> task)

Parameters

task Task<T>

The task to await.

Returns

Observable<T>

An observable that emits the task's result once it completes.

Type Parameters

T

The type of the task's result.

Generate<TState>(TState, Func<TState, bool>, Func<TState, TState>, IScheduler?)

Overload of Generate<TState, TResult>(TState, Func<TState, bool>, Func<TState, TState>, Func<TState, TResult>, IScheduler?) with no resultSelector — the state itself is emitted at each iteration.

public static Observable<TState> Generate<TState>(TState initialState, Func<TState, bool> condition, Func<TState, TState> iterate, IScheduler? scheduler = null)

Parameters

initialState TState

The state the loop starts with.

condition Func<TState, bool>

Tested against the current state before each iteration; the loop stops once this returns false.

iterate Func<TState, TState>

Advances the state after each emission.

scheduler IScheduler

If given, each loop step is scheduled on this scheduler instead of running synchronously.

Returns

Observable<TState>

An observable that emits the state itself at each iteration, then completes.

Type Parameters

TState

The type of the loop state, and of the emitted values.

Generate<TState>(TState, Func<TState, TState>, IScheduler?)

Overload of Generate<TState, TResult>(TState, Func<TState, bool>, Func<TState, TState>, Func<TState, TResult>, IScheduler?) with no condition and no resultSelector — the loop never stops on its own and the state itself is emitted (pair with e.g. Take downstream). Deliberately not overloaded further to accept a resultSelector without a condition too: with generic Func parameters of matching arity, C# overload resolution cannot always tell such an overload apart from this one (e.g. a throw-expression lambda, whose inferred return type is ambiguous) — pass condition: _ => true to the full overload instead if a custom resultSelector is needed on an otherwise-infinite generator.

public static Observable<TState> Generate<TState>(TState initialState, Func<TState, TState> iterate, IScheduler? scheduler = null)

Parameters

initialState TState

The state the loop starts with.

iterate Func<TState, TState>

Advances the state after each emission.

scheduler IScheduler

If given, each loop step is scheduled on this scheduler instead of running synchronously.

Returns

Observable<TState>

An observable that emits the state itself at each iteration, forever.

Type Parameters

TState

The type of the loop state, and of the emitted values.

Generate<TState, TResult>(TState, Func<TState, bool>, Func<TState, TState>, Func<TState, TResult>, IScheduler?)

Generates an Observable<T> by running a state-driven loop: while condition holds for the current state, emits resultSelector applied to that state, then advances the state via iterate. Runs synchronously (like a for loop) when scheduler is null, checking IsDisposed before each iteration; otherwise each step is scheduled one at a time via scheduler, so the loop can be interleaved with other scheduled work and cancelled between steps.

public static Observable<TResult> Generate<TState, TResult>(TState initialState, Func<TState, bool> condition, Func<TState, TState> iterate, Func<TState, TResult> resultSelector, IScheduler? scheduler = null)

Parameters

initialState TState

The state the loop starts with.

condition Func<TState, bool>

Tested against the current state before each iteration; the loop stops (and the observable completes) once this returns false.

iterate Func<TState, TState>

Advances the state after each emission.

resultSelector Func<TState, TResult>

Projects the current state into the value to emit for this iteration.

scheduler IScheduler

If given, each loop step is scheduled on this scheduler instead of running synchronously.

Returns

Observable<TResult>

An observable that emits one value per iteration of the loop, then completes. Errors if condition, iterate, or resultSelector throws.

Type Parameters

TState

The type of the loop state.

TResult

The type of the emitted values.

Identity<T>(T)

Returns value unchanged. Useful as a default/no-op projection where an operator requires a selector function.

public static T Identity<T>(T value)

Parameters

value T

The value to return.

Returns

T

value, unchanged.

Type Parameters

T

The type of the value.

Iif<T>(Func<bool>, Observable<T>, Observable<T>)

Creates an Observable<T> that, at subscribe time, evaluates condition and subscribes to trueSource if it returns true, or falseSource otherwise. condition is deliberately not evaluated until subscription (like Defer<T>(Func<Observable<T>>), which this is implemented on top of), so the same Observable<T> instance can pick a different branch for each subscriber.

public static Observable<T> Iif<T>(Func<bool> condition, Observable<T> trueSource, Observable<T> falseSource)

Parameters

condition Func<bool>

Evaluated once per subscription to choose the branch.

trueSource Observable<T>

Subscribed to if condition returns true.

falseSource Observable<T>

Subscribed to if condition returns false.

Returns

Observable<T>

An observable that mirrors whichever branch condition selects.

Type Parameters

T

The element type shared by both branches.

Interval(TimeSpan, IScheduler?)

Creates an Observable<long> that emits an incrementing counter (starting at 0) on every tick of a fixed period, forever, until unsubscribed.

public static Observable<long> Interval(TimeSpan period, IScheduler? scheduler = null)

Parameters

period TimeSpan

The fixed period between ticks. A negative value is treated as zero.

scheduler IScheduler

The scheduler to use for timing; defaults to Instance when null.

Returns

Observable<long>

An observable that emits 0, 1, 2, ... on every tick of period. Never completes on its own.

Merge<T>(params Observable<T>[])

Creates an Observable<T> that subscribes to all sources concurrently and emits every value from every source as it arrives, completing once all sources have completed.

public static Observable<T> Merge<T>(params Observable<T>[] sources)

Parameters

sources Observable<T>[]

The sources to merge together.

Returns

Observable<T>

An observable that emits the interleaved values of every source.

Type Parameters

T

The type of the emitted values.

Remarks

Each source is subscribed via SubscribeChild<TSource, TResult>(Observable<TSource>, Subscriber<TResult>, Action<TSource>?, Action<Exception>?, Action?) -- exactly one, stable subscription per source for the whole lifetime of the operator (never resubscribed), which is what that helper is for. This is also what lets a downstream disposal (e.g. an early-completing Take) cascade up and stop a fully-synchronous, self-checking source mid-loop, instead of only once the whole synchronous call stack has unwound -- found and fixed alongside the equivalent bug in Concat<T>(params Observable<T>[]) (see CLAUDE.md's Learnings), which predated M6's disposal-cascade fix since both are creation functions, not operator extension methods.

Never<T>()

Creates an Observable<T> that never emits, errors, or completes.

public static Observable<T> Never<T>()

Returns

Observable<T>

An observable that never produces a notification.

Type Parameters

T

The (unused) element type, needed only so the result can be composed with other Observable<T> sources of the same type.

Noop()

Does nothing. Useful as a default callback where an operator requires a delegate (e.g. an ignored onNext/onComplete handler).

public static void Noop()

Of<T>(params T[])

Creates an Observable<T> that synchronously emits each of the given values, in order, then completes.

public static Observable<T> Of<T>(params T[] values)

Parameters

values T[]

The values to emit.

Returns

Observable<T>

An observable that emits each value, then completes.

Type Parameters

T

The type of the emitted values.

OnErrorResumeNext<T>(params Observable<T>[])

Creates an Observable<T> that subscribes to each of sources in order, moving to the next source as soon as the current one either completes or errors — unlike Concat<T>(params Observable<T>[]), which stops (and forwards the error) the first time a source errors. The resulting observable completes once every source has been exhausted and never itself errors, no matter how many of the sources errored along the way.

public static Observable<T> OnErrorResumeNext<T>(params Observable<T>[] sources)

Parameters

sources Observable<T>[]

The sources to subscribe to sequentially. An empty array completes immediately, matching Empty<T>().

Returns

Observable<T>

An observable that emits every source's values in sequence, moving past errors instead of forwarding them, completing once every source has ended.

Type Parameters

T

The type of the emitted values.

Remarks

This deliberately does not use the same "resubscribe as an unconditional teardown action" trick rxjs's own implementation uses internally (see rxjs 7.8.2's observable/onErrorResumeNext.ts): there, the per-source child subscriber resubscribes to the next source as one of its own registered teardown actions, which — because an external unsubscribe of the outer observable cascades down and disposes that same child subscriber — would also (incorrectly) advance to the next source on a plain external unsubscribe, not just on the current source's own completion or error. Here, moving to the next source is triggered directly from inside the current source's onError/onComplete callbacks only (matching the pattern Retry<T>(Observable<T>, int, TimeSpan?, IScheduler?, bool) uses for its own per-attempt resubscription), so an external unsubscribe correctly stops the whole chain instead of skipping ahead.

Race<T>(params Observable<T>[])

Creates an Observable<T> that subscribes to all sources at once and mirrors whichever one emits, errors, or completes first; every other source is unsubscribed as soon as one "wins".

public static Observable<T> Race<T>(params Observable<T>[] sources)

Parameters

sources Observable<T>[]

The candidate sources to race against each other.

Returns

Observable<T>

An observable that mirrors the first source to produce a notification.

Type Parameters

T

The type of the emitted values.

Range(int)

Creates an Observable<int> that synchronously emits count sequential integers, starting at 0, then completes. Equivalent to Range(int, int) with start of 0.

public static Observable<int> Range(int count)

Parameters

count int

How many values to emit. If zero or negative, no values are emitted and the observable completes immediately.

Returns

Observable<int>

An observable that emits 0, 1, ..., count-1, then completes.

Range(int, int)

Creates an Observable<int> that synchronously emits count sequential integers, starting at start, then completes.

public static Observable<int> Range(int start, int count)

Parameters

start int

The first value to emit.

count int

How many values to emit. If zero or negative, no values are emitted and the observable completes immediately.

Returns

Observable<int>

An observable that emits start, start+1, ..., start+count-1, then completes.

ThrowError<T>(Func<Exception>)

Creates an Observable<T> that immediately errors with the exception produced by errorFactory, without ever emitting a value.

public static Observable<T> ThrowError<T>(Func<Exception> errorFactory)

Parameters

errorFactory Func<Exception>

Invoked once per subscription to produce the exception to error with.

Returns

Observable<T>

An observable that errors immediately.

Type Parameters

T

The (unused) element type, needed only so the result can be composed with other Observable<T> sources of the same type.

Timer(TimeSpan, IScheduler?)

Creates an Observable<T> that emits a single value (0) after dueTime elapses, then completes.

public static Observable<long> Timer(TimeSpan dueTime, IScheduler? scheduler = null)

Parameters

dueTime TimeSpan

How long to wait before emitting.

scheduler IScheduler

The scheduler to use for timing; defaults to Instance when null.

Returns

Observable<long>

An observable that emits once after the given delay.

Using<TSource, TResource>(Func<TResource>, Func<TResource, Observable<TSource>>)

Creates an Observable<T> that creates a resource via resourceFactory at subscribe time, uses observableFactory to build the actual source from that resource, and disposes the resource once the subscription ends — whichever of complete, error, or unsubscribe comes first. A fresh resource (and a fresh source) is created independently for every subscription; neither is shared across subscribers. Mirrors rxjs's using.

public static Observable<TSource> Using<TSource, TResource>(Func<TResource> resourceFactory, Func<TResource, Observable<TSource>> observableFactory) where TResource : IDisposable

Parameters

resourceFactory Func<TResource>

Invoked once per subscription to create the resource.

observableFactory Func<TResource, Observable<TSource>>

Invoked once per subscription, with the resource just created, to build the source observable.

Returns

Observable<TSource>

An observable that mirrors the source built by observableFactory, disposing the resource when the subscription ends.

Type Parameters

TSource

The type of the emitted values.

TResource

The resource type, disposed when the subscription ends.

Remarks

Deviates from rxjs's using in one respect: rxjs's resource factory may return nothing at all (no resource), and the "resource" only needs a structural unsubscribe() method. C# has no equivalent to an optional structural type here, so this overload requires TResource to implement IDisposable directly — pass a resource whose IDisposable.Dispose is a no-op if no real cleanup is needed. If observableFactory throws, the resource — already created by resourceFactory by that point — is still disposed before the error is forwarded; if resourceFactory itself throws, there is no resource to dispose and the error is simply forwarded (via the same synchronous-exception-to-OnError path every Observable<T> subscribe delegate already gets).

Zip<T>(params Observable<T>[])

Waits for every source to emit at a given index, then emits the combined values as a list, positionally. Same-type-only for now (unlike rxjs's heterogeneously-typed tuple overloads) — C# has no variadic generics; add typed 2/3/4-arg overloads later if a real use case needs mixed element types.

public static Observable<IReadOnlyList<T>> Zip<T>(params Observable<T>[] sources)

Parameters

sources Observable<T>[]

The sources to zip together, positionally.

Returns

Observable<IReadOnlyList<T>>

An observable that emits a list of the Nth value from every source, in order, completing once any source has completed and been fully drained.

Type Parameters

T

The element type shared by every source.