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
TThe type of the values this observable emits.
- Inheritance
-
System.ObjectObservable<T>
- Extension Methods
-
RxExtensions.RaceWithSignalAndTimer<T>(Observable<T>, TimeSpan, Func<Exception>?, CancellationToken)
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
subscribeAction<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
subscribeFunc<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
observerIObserver<T>The observer to receive notifications. Wrapped in a Subscriber<T> unless it already is one.
Returns
- IDisposable
A disposable that unsubscribes
observerfrom 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
onNextAction<T>?Invoked for each emitted value.
onErrorAction<Exception>?Invoked if the source errors.
onCompleteAction?Invoked if the source completes normally.
Returns
- IDisposable
A disposable that unsubscribes from this observable.