Class ObservableExtensions
- Namespace
- Cratis.Reactive
- Assembly
- Cratis.Fundamentals.dll
Holds extension methods for System.Reactive.Subjects.ISubject<T>.
public static class ObservableExtensions
- Inheritance
-
ObservableExtensions
- Inherited Members
Methods
CompletedBy<TResult>(ISubject<TResult>, CancellationToken)
Completes the subject when the CancellationToken is cancelled.
public static ISubject<TResult> CompletedBy<TResult>(this ISubject<TResult> subject, CancellationToken cancellationToken)
Parameters
subjectISubject<TResult>The subject to complete.
cancellationTokenCancellationTokenThe cancellation token to observe.
Returns
- ISubject<TResult>
The subject.
Type Parameters
TResultType of result.
InvokeAndWrapWithSubject<TResult>(object, Func<CancellationToken, IObservable<TResult>>)
Invokes an action and wraps the observable result in a subject providing, with a cancellation token passed to the action that cancels when the subject is completed.
public static ISubject<TResult> InvokeAndWrapWithSubject<TResult>(this object instance, Func<CancellationToken, IObservable<TResult>> action)
Parameters
instanceobjectThe instance to extend.
actionFunc<CancellationToken, IObservable<TResult>>The action to invoke that returns an observable.
Returns
- ISubject<TResult>
The subject.
Type Parameters
TResultType of result.
Remarks
The returned subject replays its most recent value to whoever subscribes to it. Callers wrap an observable here and hand the subject on to a consumer that subscribes later, so a source emitting synchronously while it is being subscribed - a System.Reactive.Subjects.BehaviorSubject<T> seed, a System.Reactive.Subjects.ReplaySubject<T> buffer, anything backed by in-memory state - would otherwise emit into a subject nobody is listening to yet and the value would be lost for good.
InvokeAndWrapWithTransformSubject<TResult, TSource>(object, Func<CancellationToken, IObservable<TSource>>, Func<TSource, TResult>)
Invokes an action and wraps the observable result in a subject providing, with a cancellation token passed to the action that cancels when the subject is completed.
public static ISubject<TResult> InvokeAndWrapWithTransformSubject<TResult, TSource>(this object instance, Func<CancellationToken, IObservable<TSource>> action, Func<TSource, TResult> transform)
Parameters
instanceobjectThe instance to extend.
actionFunc<CancellationToken, IObservable<TSource>>The action to invoke that returns an observable.
transformFunc<TSource, TResult>The transform to apply to the observable result.
Returns
- ISubject<TResult>
The subject.
Type Parameters
TResultType of result.
TSourceType of source.
Remarks
The returned subject replays its most recent value - see InvokeAndWrapWithSubject<TResult>(object, Func<CancellationToken, IObservable<TResult>>) for why.