Table of Contents

Class Observable<T>

Namespace
RxSharp
Assembly
RxSharp.dll

A push-based sequence of values. Mirrors rxjs's Observable.

public sealed class Observable<T> : IObservable<T>

Type Parameters

T

The type of the values this observable emits.

Inheritance
System.Object
Observable<T>
Extension Methods

Constructors

Observable(Action<Subscriber<T>>)

Initializes a new instance of the Observable<T> class from a subscribe action that registers its own teardown logic on the Subscriber<T> it receives (via Add(IDisposable)) instead of returning a disposable.

public Observable(Action<Subscriber<T>> subscribe)

Parameters

subscribe Action<Subscriber<T>>

Invoked once per subscription with the Subscriber<T> to push notifications to.

Observable(Func<Subscriber<T>, IDisposable?>)

Initializes a new instance of the Observable<T> class from a subscribe function that returns the teardown logic for the subscription (or null if none is needed).

public Observable(Func<Subscriber<T>, IDisposable?> subscribe)

Parameters

subscribe Func<Subscriber<T>, IDisposable?>

Invoked once per subscription with the Subscriber<T> to push notifications to; returns the disposable to run on unsubscribe, if any.

Methods

Subscribe(IObserver<T>)

Subscribes the given observer to this observable, invoking the subscribe delegate passed to the constructor. If that delegate throws synchronously, the exception is forwarded to observer via IObserver<T>.OnError(Exception) instead of propagating to the caller.

public IDisposable Subscribe(IObserver<T> observer)

Parameters

observer IObserver<T>

The observer to receive notifications. Wrapped in a Subscriber<T> unless it already is one.

Returns

IDisposable

A disposable that unsubscribes observer from this observable.

Subscribe(Action<T>?, Action<Exception>?, Action?)

Subscribes to this observable using bare delegates instead of an IObserver<T> instance. Any callback left null is simply not invoked for that kind of notification (an omitted onError falls back to OnUnhandledError).

public IDisposable Subscribe(Action<T>? onNext = null, Action<Exception>? onError = null, Action? onComplete = null)

Parameters

onNext Action<T>?

Invoked for each emitted value.

onError Action<Exception>?

Invoked if the source errors.

onComplete Action?

Invoked if the source completes normally.

Returns

IDisposable

A disposable that unsubscribes from this observable.