Class ObservableAsync
- Namespace
- ReactiveUI.Extensions.Async
- Assembly
- ReactiveUI.Extensions.dll
Provides factory methods for creating asynchronous observables and background jobs that emit values to observers asynchronously.
public static class ObservableAsync
- Inheritance
-
ObservableAsync
Remarks
The methods in this class allow developers to construct asynchronous observables by supplying custom subscription logic or background jobs. Observables created with these methods support asynchronous notification and cancellation, enabling integration with modern async workflows. Use these methods to bridge asynchronous producers with consumers following the observer pattern.
Methods
AggregateAsync<T, TAcc>(IObservableAsync<T>, TAcc, Func<TAcc, T, CancellationToken, ValueTask<TAcc>>, CancellationToken)
Applies an asynchronous accumulator function over the observable sequence, returning the final accumulated value when the sequence completes.
public static ValueTask<TAcc> AggregateAsync<T, TAcc>(this IObservableAsync<T> @this, TAcc seed, Func<TAcc, T, CancellationToken, ValueTask<TAcc>> accumulator, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>seedTAccThe initial accumulator value.
accumulatorFunc<TAcc, T, CancellationToken, ValueTask<TAcc>>An asynchronous accumulator function to invoke on each element. Receives the current accumulated value, the current element, and a cancellation token.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the operation.
Returns
- ValueTask<TAcc>
A task representing the asynchronous operation, containing the final accumulated value.
Type Parameters
TTAccThe type of the accumulated value.
Exceptions
- ArgumentNullException
Thrown if
accumulatoris null.
AggregateAsync<T, TAcc>(IObservableAsync<T>, TAcc, Func<TAcc, T, TAcc>, CancellationToken)
Applies an accumulator function over the observable sequence, returning the final accumulated value when the sequence completes.
public static ValueTask<TAcc> AggregateAsync<T, TAcc>(this IObservableAsync<T> @this, TAcc seed, Func<TAcc, T, TAcc> accumulator, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>seedTAccThe initial accumulator value.
accumulatorFunc<TAcc, T, TAcc>An accumulator function to invoke on each element. Receives the current accumulated value and the current element.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the operation.
Returns
- ValueTask<TAcc>
A task representing the asynchronous operation, containing the final accumulated value.
Type Parameters
TTAccThe type of the accumulated value.
Exceptions
- ArgumentNullException
Thrown if
accumulatoris null.
AggregateAsync<T, TAcc, TResult>(IObservableAsync<T>, TAcc, Func<TAcc, T, TAcc>, Func<TAcc, TResult>, CancellationToken)
Applies an accumulator function over the observable sequence with a seed value, then applies a result selector to the final accumulated value.
public static ValueTask<TResult> AggregateAsync<T, TAcc, TResult>(this IObservableAsync<T> @this, TAcc seed, Func<TAcc, T, TAcc> accumulator, Func<TAcc, TResult> resultSelector, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>seedTAccThe initial accumulator value.
accumulatorFunc<TAcc, T, TAcc>An accumulator function to invoke on each element.
resultSelectorFunc<TAcc, TResult>A function to transform the final accumulated value into the result value.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the operation.
Returns
- ValueTask<TResult>
A task representing the asynchronous operation, containing the transformed result.
Type Parameters
TTAccThe type of the intermediate accumulated value.
TResultThe type of the result value.
Exceptions
- ArgumentNullException
Thrown if
accumulatororresultSelectoris null.
AllAsync<T>(IObservableAsync<T>, Func<T, bool>, CancellationToken)
Asynchronously determines whether all elements in the sequence satisfy the specified predicate.
public static ValueTask<bool> AllAsync<T>(this IObservableAsync<T> @this, Func<T, bool> predicate, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>predicateFunc<T, bool>A function to test each element for a condition. The method evaluates this predicate for each element in the sequence.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<bool>
A task that represents the asynchronous operation. The task result contains true if every element of the sequence passes the test in the specified predicate, or if the sequence is empty; otherwise, false.
Type Parameters
T
Exceptions
- ArgumentNullException
Thrown if
predicateis null.
AnyAsync<T>(IObservableAsync<T>, Func<T, bool>?, CancellationToken)
Asynchronously determines whether any element in the sequence satisfies the specified predicate.
public static ValueTask<bool> AnyAsync<T>(this IObservableAsync<T> @this, Func<T, bool>? predicate, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>predicateFunc<T, bool>A function to test each element for a condition. If null, the method checks whether the sequence contains any elements.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<bool>
A task that represents the asynchronous operation. The task result contains true if any element satisfies the predicate or, if the predicate is null, if the sequence contains any elements; otherwise, false.
Type Parameters
T
AnyAsync<T>(IObservableAsync<T>, CancellationToken)
Asynchronously determines whether the source contains any elements.
public static ValueTask<bool> AnyAsync<T>(this IObservableAsync<T> @this, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<bool>
A task that represents the asynchronous operation. The task result contains true if the source contains any elements; otherwise, false.
Type Parameters
T
Cast<T, TResult>(IObservableAsync<T>)
Projects each element of the observable sequence to the specified result type by performing a runtime cast.
public static IObservableAsync<TResult> Cast<T, TResult>(this IObservableAsync<T> @this) where T : notnull where TResult : notnull
Parameters
thisIObservableAsync<T>
Returns
- IObservableAsync<TResult>
An observable sequence whose elements are the result of casting each element of the source sequence to
TResult.
Type Parameters
TTResultThe type to which the elements of the sequence are cast.
Remarks
If an element in the source sequence cannot be cast to TResult, the sequence completes with a failure containing the exception. This method is useful for
working with sequences of objects when the actual element type is known at runtime.
CatchAndIgnoreErrorResume<T>(IObservableAsync<T>, Func<Exception, IObservableAsync<T>>)
Continues the observable sequence with an alternative sequence provided by the specified handler when an error occurs, and ignores the error after invoking the handler.
public static IObservableAsync<T> CatchAndIgnoreErrorResume<T>(this IObservableAsync<T> source, Func<Exception, IObservableAsync<T>> handler) where T : notnull
Parameters
sourceIObservableAsync<T>handlerFunc<Exception, IObservableAsync<T>>A function that receives the exception and returns an alternative observable sequence to resume with after an error occurs.
Returns
- IObservableAsync<T>
An observable sequence that resumes with the sequence returned by the handler when an error is encountered, and ignores the error after handling.
Type Parameters
T
Remarks
If an error occurs and the handler is invoked, the error is also reported to the global unhandled exception handler before being ignored. This method allows the sequence to continue without propagating the error to subscribers.
Catch<T>(IObservableAsync<T>, Func<Exception, IObservableAsync<T>>, Func<Exception, CancellationToken, ValueTask>?)
Creates a new observable sequence that continues with a handler-provided sequence when an exception occurs in the source sequence.
public static IObservableAsync<T> Catch<T>(this IObservableAsync<T> source, Func<Exception, IObservableAsync<T>> handler, Func<Exception, CancellationToken, ValueTask>? onErrorResume = null) where T : notnull
Parameters
sourceIObservableAsync<T>handlerFunc<Exception, IObservableAsync<T>>A function that receives the exception thrown by the source sequence and returns an alternative observable sequence to continue with.
onErrorResumeFunc<Exception, CancellationToken, ValueTask>An optional asynchronous callback invoked when an error occurs. If not specified, the observer's default error handler is used.
Returns
- IObservableAsync<T>
An observable sequence that emits items from the source sequence, or from the handler-provided sequence if an exception is encountered.
Type Parameters
T
Remarks
Use this method to recover from errors in the source sequence by switching to an alternative observable sequence. The handler function is called with the exception, allowing custom error recovery logic. If the handler itself throws an exception, the resulting sequence completes with that exception.
Exceptions
- ArgumentNullException
Thrown if the source sequence or
handleris null.
CombineLatest<T1, T2, TResult>(IObservableAsync<T1>, IObservableAsync<T2>, Func<T1, T2, TResult>)
Combines two asynchronous observable sequences and emits a result each time either sequence produces a value, using the specified selector function.
public static IObservableAsync<TResult> CombineLatest<T1, T2, TResult>(this IObservableAsync<T1> src1, IObservableAsync<T2> src2, Func<T1, T2, TResult> selector)
Parameters
src1IObservableAsync<T1>The first asynchronous observable sequence to combine.
src2IObservableAsync<T2>The second asynchronous observable sequence to combine.
selectorFunc<T1, T2, TResult>A function that projects a result value from the latest values of both observable sequences.
Returns
- IObservableAsync<TResult>
An asynchronous observable sequence that emits values resulting from applying the selector function to the latest values from both source sequences.
Type Parameters
T1The type of the elements in the first observable sequence.
T2The type of the elements in the second observable sequence.
TResultThe type of the result produced by the selector function.
Remarks
The returned sequence emits a value each time either source sequence produces a new value, after both sequences have produced at least one value. The selector function is invoked with the most recent values from each sequence. If either source sequence completes, the combined sequence completes as well.
CombineLatest<T1, T2, T3, TResult>(IObservableAsync<T1>, IObservableAsync<T2>, IObservableAsync<T3>, Func<T1, T2, T3, TResult>)
Combines the latest values from three asynchronous observable sequences and projects them into a new result using the specified selector function.
public static IObservableAsync<TResult> CombineLatest<T1, T2, T3, TResult>(this IObservableAsync<T1> src1, IObservableAsync<T2> src2, IObservableAsync<T3> src3, Func<T1, T2, T3, TResult> selector)
Parameters
src1IObservableAsync<T1>The first source observable sequence whose latest value will be combined.
src2IObservableAsync<T2>The second source observable sequence whose latest value will be combined.
src3IObservableAsync<T3>The third source observable sequence whose latest value will be combined.
selectorFunc<T1, T2, T3, TResult>A function that receives the latest values from each source sequence and returns a projected result.
Returns
- IObservableAsync<TResult>
An asynchronous observable sequence that emits a result each time any of the source sequences produces a new value, using the latest values from all sources.
Type Parameters
T1The type of the elements in the first source observable sequence.
T2The type of the elements in the second source observable sequence.
T3The type of the elements in the third source observable sequence.
TResultThe type of the result produced by the selector function.
Remarks
The returned sequence does not emit a value until all source sequences have produced at least one value. Subsequent emissions occur whenever any source sequence produces a new value, using the most recent values from all sources.
CombineLatest<T1, T2, T3, T4, TResult>(IObservableAsync<T1>, IObservableAsync<T2>, IObservableAsync<T3>, IObservableAsync<T4>, Func<T1, T2, T3, T4, TResult>)
Combines the latest values from four asynchronous observable sequences and projects them into a new result using the specified selector function.
public static IObservableAsync<TResult> CombineLatest<T1, T2, T3, T4, TResult>(this IObservableAsync<T1> src1, IObservableAsync<T2> src2, IObservableAsync<T3> src3, IObservableAsync<T4> src4, Func<T1, T2, T3, T4, TResult> selector)
Parameters
src1IObservableAsync<T1>The first source observable sequence whose latest value will be combined.
src2IObservableAsync<T2>The second source observable sequence whose latest value will be combined.
src3IObservableAsync<T3>The third source observable sequence whose latest value will be combined.
src4IObservableAsync<T4>The fourth source observable sequence whose latest value will be combined.
selectorFunc<T1, T2, T3, T4, TResult>A function that takes the latest values from each source sequence and projects them into a result.
Returns
- IObservableAsync<TResult>
An asynchronous observable sequence containing the results of combining the latest values from the four source sequences using the selector function.
Type Parameters
T1The type of the elements in the first source observable sequence.
T2The type of the elements in the second source observable sequence.
T3The type of the elements in the third source observable sequence.
T4The type of the elements in the fourth source observable sequence.
TResultThe type of the result produced by the selector function.
Remarks
The returned sequence emits a new result each time any of the source sequences produces a value, after all sources have produced at least one value. The selector function is invoked with the most recent values from each source. If any source sequence completes or fails, the resulting sequence will also complete or fail accordingly.
CombineLatest<T1, T2, T3, T4, T5, TResult>(IObservableAsync<T1>, IObservableAsync<T2>, IObservableAsync<T3>, IObservableAsync<T4>, IObservableAsync<T5>, Func<T1, T2, T3, T4, T5, TResult>)
Combines the latest values from five asynchronous observable sequences into a single sequence using the specified selector function.
public static IObservableAsync<TResult> CombineLatest<T1, T2, T3, T4, T5, TResult>(this IObservableAsync<T1> src1, IObservableAsync<T2> src2, IObservableAsync<T3> src3, IObservableAsync<T4> src4, IObservableAsync<T5> src5, Func<T1, T2, T3, T4, T5, TResult> selector)
Parameters
src1IObservableAsync<T1>The first source observable sequence whose latest value will be combined.
src2IObservableAsync<T2>The second source observable sequence whose latest value will be combined.
src3IObservableAsync<T3>The third source observable sequence whose latest value will be combined.
src4IObservableAsync<T4>The fourth source observable sequence whose latest value will be combined.
src5IObservableAsync<T5>The fifth source observable sequence whose latest value will be combined.
selectorFunc<T1, T2, T3, T4, T5, TResult>A function that combines the latest values from each source sequence into a result value.
Returns
- IObservableAsync<TResult>
An asynchronous observable sequence that emits values resulting from applying the selector function to the latest values from each source sequence.
Type Parameters
T1The type of the elements in the first source observable sequence.
T2The type of the elements in the second source observable sequence.
T3The type of the elements in the third source observable sequence.
T4The type of the elements in the fourth source observable sequence.
T5The type of the elements in the fifth source observable sequence.
TResultThe type of the result produced by the selector function.
Remarks
The resulting sequence emits a new value each time any of the source sequences produces a value, after all sources have emitted at least one value. If any source sequence completes or fails, the resulting sequence will also complete or fail accordingly.
CombineLatest<T1, T2, T3, T4, T5, T6, TResult>(IObservableAsync<T1>, IObservableAsync<T2>, IObservableAsync<T3>, IObservableAsync<T4>, IObservableAsync<T5>, IObservableAsync<T6>, Func<T1, T2, T3, T4, T5, T6, TResult>)
Combines the latest values from six asynchronous observable sources into a single observable sequence, using the specified selector function to produce results.
public static IObservableAsync<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, TResult>(this IObservableAsync<T1> src1, IObservableAsync<T2> src2, IObservableAsync<T3> src3, IObservableAsync<T4> src4, IObservableAsync<T5> src5, IObservableAsync<T6> src6, Func<T1, T2, T3, T4, T5, T6, TResult> selector)
Parameters
src1IObservableAsync<T1>The first source observable whose latest value will be combined.
src2IObservableAsync<T2>The second source observable whose latest value will be combined.
src3IObservableAsync<T3>The third source observable whose latest value will be combined.
src4IObservableAsync<T4>The fourth source observable whose latest value will be combined.
src5IObservableAsync<T5>The fifth source observable whose latest value will be combined.
src6IObservableAsync<T6>The sixth source observable whose latest value will be combined.
selectorFunc<T1, T2, T3, T4, T5, T6, TResult>A function that combines the latest values from each source observable into a result value.
Returns
- IObservableAsync<TResult>
An observable sequence that emits a result each time any of the source observables produces a new value, after all sources have emitted at least one value.
Type Parameters
T1The type of the elements in the first source observable.
T2The type of the elements in the second source observable.
T3The type of the elements in the third source observable.
T4The type of the elements in the fourth source observable.
T5The type of the elements in the fifth source observable.
T6The type of the elements in the sixth source observable.
TResultThe type of the result elements produced by the selector function.
Remarks
The resulting observable will not emit any values until all six source observables have produced at least one value. Subsequent emissions occur whenever any source produces a new value, using the latest values from all sources. If any source completes or fails, the resulting observable will complete or fail accordingly.
CombineLatest<T1, T2, T3, T4, T5, T6, T7, TResult>(IObservableAsync<T1>, IObservableAsync<T2>, IObservableAsync<T3>, IObservableAsync<T4>, IObservableAsync<T5>, IObservableAsync<T6>, IObservableAsync<T7>, Func<T1, T2, T3, T4, T5, T6, T7, TResult>)
Combines the latest values from seven asynchronous observable sources into a single observable sequence, using the specified selector function to produce results whenever any source emits a new value.
public static IObservableAsync<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, TResult>(this IObservableAsync<T1> src1, IObservableAsync<T2> src2, IObservableAsync<T3> src3, IObservableAsync<T4> src4, IObservableAsync<T5> src5, IObservableAsync<T6> src6, IObservableAsync<T7> src7, Func<T1, T2, T3, T4, T5, T6, T7, TResult> selector)
Parameters
src1IObservableAsync<T1>The first asynchronous observable source whose latest value will be combined.
src2IObservableAsync<T2>The second asynchronous observable source whose latest value will be combined.
src3IObservableAsync<T3>The third asynchronous observable source whose latest value will be combined.
src4IObservableAsync<T4>The fourth asynchronous observable source whose latest value will be combined.
src5IObservableAsync<T5>The fifth asynchronous observable source whose latest value will be combined.
src6IObservableAsync<T6>The sixth asynchronous observable source whose latest value will be combined.
src7IObservableAsync<T7>The seventh asynchronous observable source whose latest value will be combined.
selectorFunc<T1, T2, T3, T4, T5, T6, T7, TResult>A function that combines the latest values from all seven sources into a result to be emitted by the resulting observable sequence.
Returns
- IObservableAsync<TResult>
An asynchronous observable sequence that emits results produced by the selector function whenever any of the seven sources emits a new value, after all sources have emitted at least one value.
Type Parameters
T1The type of the elements emitted by the first observable source.
T2The type of the elements emitted by the second observable source.
T3The type of the elements emitted by the third observable source.
T4The type of the elements emitted by the fourth observable source.
T5The type of the elements emitted by the fifth observable source.
T6The type of the elements emitted by the sixth observable source.
T7The type of the elements emitted by the seventh observable source.
TResultThe type of the result produced by the selector function.
Remarks
The resulting sequence does not emit a value until each source has produced at least one value. Subsequent emissions occur whenever any source produces a new value, using the latest values from all sources. If any source completes or fails, the resulting sequence will complete or propagate the error accordingly.
CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(IObservableAsync<T1>, IObservableAsync<T2>, IObservableAsync<T3>, IObservableAsync<T4>, IObservableAsync<T5>, IObservableAsync<T6>, IObservableAsync<T7>, IObservableAsync<T8>, Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult>)
Combines the latest values from eight asynchronous observable sources into a single observable sequence, using the specified selector function to produce results.
public static IObservableAsync<TResult> CombineLatest<T1, T2, T3, T4, T5, T6, T7, T8, TResult>(this IObservableAsync<T1> src1, IObservableAsync<T2> src2, IObservableAsync<T3> src3, IObservableAsync<T4> src4, IObservableAsync<T5> src5, IObservableAsync<T6> src6, IObservableAsync<T7> src7, IObservableAsync<T8> src8, Func<T1, T2, T3, T4, T5, T6, T7, T8, TResult> selector)
Parameters
src1IObservableAsync<T1>The first source observable whose latest value will be combined.
src2IObservableAsync<T2>The second source observable whose latest value will be combined.
src3IObservableAsync<T3>The third source observable whose latest value will be combined.
src4IObservableAsync<T4>The fourth source observable whose latest value will be combined.
src5IObservableAsync<T5>The fifth source observable whose latest value will be combined.
src6IObservableAsync<T6>The sixth source observable whose latest value will be combined.
src7IObservableAsync<T7>The seventh source observable whose latest value will be combined.
src8IObservableAsync<T8>The eighth source observable whose latest value will be combined.
selectorFunc<T1, T2, T3, T4, T5, T6, T7, T8, TResult>A function that combines the latest values from each source observable into a result value.
Returns
- IObservableAsync<TResult>
An observable sequence that emits a result each time any of the source observables produces a new value, after all sources have emitted at least one value.
Type Parameters
T1The type of the elements in the first source observable.
T2The type of the elements in the second source observable.
T3The type of the elements in the third source observable.
T4The type of the elements in the fourth source observable.
T5The type of the elements in the fifth source observable.
T6The type of the elements in the sixth source observable.
T7The type of the elements in the seventh source observable.
T8The type of the elements in the eighth source observable.
TResultThe type of the result produced by the selector function.
Remarks
The resulting observable will not emit a value until each source observable has produced at least one value. Subsequent emissions occur whenever any source produces a new value, using the latest values from all sources. If any source observable completes or fails, the resulting sequence will complete or fail accordingly.
Concat<T>(IObservableAsync<IObservableAsync<T>>)
Concatenates a sequence of asynchronous observable sequences into a single observable sequence, subscribing to each inner sequence in order only after the previous one completes.
public static IObservableAsync<T> Concat<T>(this IObservableAsync<IObservableAsync<T>> @this)
Parameters
thisIObservableAsync<IObservableAsync<T>>The source observable sequence whose elements are themselves observable sequences to be concatenated. Cannot be null.
Returns
- IObservableAsync<T>
An observable sequence that emits the elements of each inner observable sequence in order, waiting for each to complete before subscribing to the next.
Type Parameters
TThe type of the elements emitted by the inner observable sequences.
Remarks
If any inner observable sequence signals an error, the resulting sequence will propagate that error and terminate immediately. The concatenation is performed in a deferred and sequential manner, ensuring that only one inner sequence is active at a time.
Concat<T>(IObservableAsync<T>, IObservableAsync<T>)
Concatenates two asynchronous observable sequences into a single sequence that emits all elements from the first sequence, followed by all elements from the second sequence.
public static IObservableAsync<T> Concat<T>(this IObservableAsync<T> @this, IObservableAsync<T> second)
Parameters
thisIObservableAsync<T>The first observable sequence to concatenate. Cannot be null.
secondIObservableAsync<T>The second observable sequence to concatenate. Cannot be null.
Returns
- IObservableAsync<T>
An observable sequence that emits all elements from the first sequence, followed by all elements from the second sequence.
Type Parameters
TThe type of the elements in the observable sequences.
Remarks
The resulting sequence emits all items from the first observable before subscribing to and emitting items from the second observable. If either sequence signals an error, the concatenation terminates and the error is propagated to observers.
Concat<T>(IEnumerable<IObservableAsync<T>>)
Concatenates multiple asynchronous observable sequences into a single sequence that emits items from each source in order.
public static IObservableAsync<T> Concat<T>(this IEnumerable<IObservableAsync<T>> @this)
Parameters
thisIEnumerable<IObservableAsync<T>>A collection of asynchronous observable sequences to concatenate. Cannot be null.
Returns
- IObservableAsync<T>
An asynchronous observable sequence that emits all items from each source sequence in the order they appear in the collection.
Type Parameters
TThe type of the elements in the observable sequences.
Remarks
Each source sequence is subscribed to only after the previous one completes. If any source sequence signals an error, concatenation stops and the error is propagated to the observer.
ContainsAsync<T>(IObservableAsync<T>, T, IEqualityComparer<T>?, CancellationToken)
Asynchronously determines whether the sequence contains a specified value using the given equality comparer.
public static ValueTask<bool> ContainsAsync<T>(this IObservableAsync<T> @this, T value, IEqualityComparer<T>? comparer, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>valueTThe value to locate in the sequence.
comparerIEqualityComparer<T>The equality comparer to use for comparing values, or null to use the default equality comparer for the type.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<bool>
A task that represents the asynchronous operation. The task result contains true if the value is found in the sequence; otherwise, false.
Type Parameters
T
ContainsAsync<T>(IObservableAsync<T>, T, CancellationToken)
Asynchronously determines whether the collection contains a specified value.
public static ValueTask<bool> ContainsAsync<T>(this IObservableAsync<T> @this, T value, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>valueTThe value to locate in the collection.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<bool>
A task that represents the asynchronous operation. The task result contains true if the value is found in the collection; otherwise, false.
Type Parameters
T
CountAsync<T>(IObservableAsync<T>, Func<T, bool>?, CancellationToken)
Asynchronously counts the number of elements that satisfy a specified condition.
public static ValueTask<int> CountAsync<T>(this IObservableAsync<T> @this, Func<T, bool>? predicate, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>predicateFunc<T, bool>A function to test each element for a condition. If null, all elements are counted.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<int>
A task that represents the asynchronous count operation. The task result contains the number of elements that match the predicate.
Type Parameters
T
CountAsync<T>(IObservableAsync<T>, CancellationToken)
Asynchronously returns the total number of elements in the data source.
public static ValueTask<int> CountAsync<T>(this IObservableAsync<T> @this, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous count operation.
Returns
- ValueTask<int>
A task that represents the asynchronous operation. The task result contains the number of elements in the data source.
Type Parameters
T
CreateAsBackgroundJob<T>(Func<IObserverAsync<T>, CancellationToken, ValueTask>, bool)
Creates a new observable sequence that runs the specified asynchronous job as a background task.
public static IObservableAsync<T> CreateAsBackgroundJob<T>(Func<IObserverAsync<T>, CancellationToken, ValueTask> job, bool startSynchronously = false)
Parameters
jobFunc<IObserverAsync<T>, CancellationToken, ValueTask>A delegate that defines the asynchronous job to execute. The delegate receives an observer to report results and a cancellation token to observe cancellation requests.
startSynchronouslybooltrue to start the job synchronously on the calling thread; otherwise, false to schedule it to run asynchronously.
Returns
- IObservableAsync<T>
An ObservableAsync{T} that represents the observable sequence produced by the background job.
Type Parameters
TThe type of elements produced by the observable sequence.
CreateAsBackgroundJob<T>(Func<IObserverAsync<T>, CancellationToken, ValueTask>, TaskScheduler)
Creates a new observable sequence that runs the specified asynchronous job as a background task using the provided task scheduler.
public static IObservableAsync<T> CreateAsBackgroundJob<T>(Func<IObserverAsync<T>, CancellationToken, ValueTask> job, TaskScheduler taskScheduler)
Parameters
jobFunc<IObserverAsync<T>, CancellationToken, ValueTask>A delegate that defines the asynchronous job to execute. The delegate receives an observer to report results and a cancellation token to observe cancellation requests.
taskSchedulerTaskSchedulerThe task scheduler that is used to schedule the background job.
Returns
- IObservableAsync<T>
An ObservableAsync{T} that represents the asynchronous background job and emits the results produced by the job.
Type Parameters
TThe type of the elements produced by the observable sequence.
Create<T>(Func<IObserverAsync<T>, CancellationToken, ValueTask<IAsyncDisposable>>)
Creates a new asynchronous observable sequence using the specified subscription function.
public static IObservableAsync<T> Create<T>(Func<IObserverAsync<T>, CancellationToken, ValueTask<IAsyncDisposable>> subscribeAsync)
Parameters
subscribeAsyncFunc<IObserverAsync<T>, CancellationToken, ValueTask<IAsyncDisposable>>A function that is invoked when an observer subscribes to the sequence. The function receives an asynchronous observer and a cancellation token, and returns a task that yields a disposable resource representing the subscription.
Returns
- IObservableAsync<T>
An ObservableAsync{T} that invokes the specified subscription function for each observer.
Type Parameters
TThe type of the elements produced by the observable sequence.
Remarks
The subscription function is responsible for handling observer notifications and managing the lifetime of the subscription. The returned disposable should release any resources or cancel ongoing operations when disposed.
Exceptions
- ArgumentNullException
Thrown if
subscribeAsyncis null.
Defer<T>(Func<IObservableAsync<T>>)
Returns an observable sequence that is created by invoking the specified factory function each time a new observer subscribes.
public static IObservableAsync<T> Defer<T>(Func<IObservableAsync<T>> factory)
Parameters
factoryFunc<IObservableAsync<T>>A function that returns a new instance of an observable sequence to be subscribed to for each observer.
Returns
- IObservableAsync<T>
An observable sequence whose observers trigger the invocation of the factory function upon subscription.
Type Parameters
TThe type of the elements produced by the observable sequence.
Remarks
Use this method to defer the creation of the observable sequence until an observer subscribes, ensuring that each subscription receives a fresh instance. This is useful when the observable sequence has side effects or depends on external state at the time of subscription.
Defer<T>(Func<CancellationToken, ValueTask<IObservableAsync<T>>>)
Creates a new observable sequence for each subscription by invoking the specified asynchronous factory function.
public static IObservableAsync<T> Defer<T>(Func<CancellationToken, ValueTask<IObservableAsync<T>>> factory)
Parameters
factoryFunc<CancellationToken, ValueTask<IObservableAsync<T>>>A function that receives a cancellation token and returns a task that produces an observable sequence to subscribe to.
Returns
- IObservableAsync<T>
An observable sequence that, upon each subscription, invokes the factory function to obtain the actual observable sequence to subscribe to.
Type Parameters
TThe type of the elements produced by the observable sequence.
Remarks
Use this method to defer the creation of the observable sequence until an observer subscribes. This is useful when the observable sequence depends on per-subscription state or resources, or when you want to ensure a fresh sequence for each subscriber.
Delay<T>(IObservableAsync<T>, TimeSpan, TimeProvider?)
Time-shifts the observable sequence by the specified time span. Each element notification is delayed by the specified duration.
public static IObservableAsync<T> Delay<T>(this IObservableAsync<T> @this, TimeSpan delay, TimeProvider? timeProvider = null)
Parameters
thisIObservableAsync<T>delayTimeSpanThe time span by which to delay each element notification. Must be non-negative.
timeProviderTimeProviderAn optional time provider for controlling timing. If null, System is used.
Returns
- IObservableAsync<T>
An observable sequence with element notifications time-shifted by the specified duration.
Type Parameters
T
Exceptions
- ArgumentOutOfRangeException
Thrown if
delayis negative.
DistinctBy<T, TKey>(IObservableAsync<T>, Func<T, TKey>)
Returns a sequence that contains distinct elements from the source sequence according to a specified key selector function.
public static IObservableAsync<T> DistinctBy<T, TKey>(this IObservableAsync<T> @this, Func<T, TKey> keySelector) where T : notnull where TKey : notnull
Parameters
thisIObservableAsync<T>keySelectorFunc<T, TKey>A function to extract the key for each element. Cannot be null.
Returns
- IObservableAsync<T>
An observable sequence that contains only the first occurrence of each distinct key as determined by the key selector.
Type Parameters
TTKeyThe type of the key returned by the key selector function.
Remarks
Elements are considered distinct based on the value returned by the key selector and the default equality comparer for the key type.
DistinctBy<T, TKey>(IObservableAsync<T>, Func<T, TKey>, IEqualityComparer<TKey>)
Returns an observable sequence that contains only distinct elements from the source sequence, comparing values based on a specified key and equality comparer.
public static IObservableAsync<T> DistinctBy<T, TKey>(this IObservableAsync<T> @this, Func<T, TKey> keySelector, IEqualityComparer<TKey> equalityComparer) where T : notnull where TKey : notnull
Parameters
thisIObservableAsync<T>keySelectorFunc<T, TKey>A function to extract the key for each element. Cannot be null.
equalityComparerIEqualityComparer<TKey>An equality comparer to compare keys for equality. Cannot be null.
Returns
- IObservableAsync<T>
An observable sequence that contains only the first occurrence of each distinct key as determined by the specified key selector and equality comparer.
Type Parameters
TTKeyThe type of the key used to determine the distinctness of elements.
Remarks
Elements are considered distinct based on the value returned by the keySelector function and compared using the provided equalityComparer. Only the
first occurrence of each key is included in the resulting sequence.
Exceptions
- ArgumentNullException
Thrown if
keySelectororequalityCompareris null.
DistinctUntilChangedBy<T, TKey>(IObservableAsync<T>, Func<T, TKey>)
Returns an observable sequence that emits elements from the source sequence, suppressing consecutive duplicates as determined by a key selector function.
public static IObservableAsync<T> DistinctUntilChangedBy<T, TKey>(this IObservableAsync<T> @this, Func<T, TKey> keySelector) where T : notnull where TKey : notnull
Parameters
thisIObservableAsync<T>keySelectorFunc<T, TKey>A function that extracts the comparison key from each element in the source sequence.
Returns
- IObservableAsync<T>
An observable sequence that contains only the elements from the source sequence that are not consecutive duplicates according to the specified key.
Type Parameters
TTKeyThe type of the key used to determine whether consecutive elements are considered duplicates.
Remarks
The comparison of keys uses the default equality comparer for the type TKey. Only consecutive duplicate elements are suppressed; non-consecutive duplicates are not
affected.
DistinctUntilChangedBy<T, TKey>(IObservableAsync<T>, Func<T, TKey>, IEqualityComparer<TKey>)
Returns an observable sequence that emits elements from the source sequence, suppressing consecutive duplicates as determined by a key selector and equality comparer.
public static IObservableAsync<T> DistinctUntilChangedBy<T, TKey>(this IObservableAsync<T> @this, Func<T, TKey> keySelector, IEqualityComparer<TKey> equalityComparer) where T : notnull where TKey : notnull
Parameters
thisIObservableAsync<T>keySelectorFunc<T, TKey>A function that extracts the comparison key from each element in the source sequence.
equalityComparerIEqualityComparer<TKey>An equality comparer used to compare keys for equality.
Returns
- IObservableAsync<T>
An observable sequence that contains only the elements from the source sequence that are not consecutive duplicates according to the specified key and comparer.
Type Parameters
TTKeyThe type of the key used to determine whether consecutive elements are considered duplicates.
Remarks
The first element in the sequence is always emitted. Subsequent elements are emitted
only if their key, as determined by keySelector, is not equal to the key of the
immediately preceding element, as determined by equalityComparer.
Exceptions
- ArgumentNullException
Thrown if
keySelectororequalityCompareris null.
DistinctUntilChanged<T>(IObservableAsync<T>)
Returns an observable sequence that emits only distinct consecutive elements, suppressing duplicates that are equal to the previous element.
public static IObservableAsync<T> DistinctUntilChanged<T>(this IObservableAsync<T> @this) where T : notnull
Parameters
thisIObservableAsync<T>
Returns
- IObservableAsync<T>
An observable sequence that contains only the elements from the source sequence that are not equal to their immediate predecessor.
Type Parameters
T
Remarks
Elements are compared using the default equality comparer for the type T. Only consecutive duplicate elements are suppressed; non-consecutive duplicates are not
affected.
DistinctUntilChanged<T>(IObservableAsync<T>, IEqualityComparer<T>)
Returns an observable sequence that emits elements from the source sequence only when the current element is not equal to the previous element, as determined by the specified equality comparer.
public static IObservableAsync<T> DistinctUntilChanged<T>(this IObservableAsync<T> @this, IEqualityComparer<T> equalityComparer) where T : notnull
Parameters
thisIObservableAsync<T>equalityComparerIEqualityComparer<T>An equality comparer used to determine whether consecutive elements are considered equal.
Returns
- IObservableAsync<T>
An observable sequence that contains only distinct consecutive elements from the source sequence, as determined by the specified equality comparer.
Type Parameters
T
Remarks
Use this method to suppress consecutive duplicate elements in the sequence. Only elements that differ from their immediate predecessor, according to the provided comparer, are emitted to observers.
Exceptions
- ArgumentNullException
Thrown if
equalityCompareris null.
Distinct<T>(IObservableAsync<T>)
Returns a sequence that contains only distinct elements from the source sequence, using the default equality comparer for the element type.
public static IObservableAsync<T> Distinct<T>(this IObservableAsync<T> @this) where T : notnull
Parameters
thisIObservableAsync<T>
Returns
- IObservableAsync<T>
An observable sequence that contains distinct elements from the source sequence.
Type Parameters
T
Remarks
Elements are considered distinct based on the default equality comparer for type T. The order of elements is preserved.
Distinct<T>(IObservableAsync<T>, IEqualityComparer<T>)
Returns an observable sequence that contains only distinct elements from the source sequence, using the specified equality comparer to determine uniqueness.
public static IObservableAsync<T> Distinct<T>(this IObservableAsync<T> @this, IEqualityComparer<T> equalityComparer) where T : notnull
Parameters
thisIObservableAsync<T>equalityComparerIEqualityComparer<T>An equality comparer to compare values for equality. If null, the default equality comparer for the type is used.
Returns
- IObservableAsync<T>
An observable sequence that emits each distinct element from the source sequence, in the order in which they are received.
Type Parameters
T
Remarks
Only the first occurrence of each element, as determined by the specified equality comparer, is emitted to observers. Subsequent duplicate elements are ignored.
Do<T>(IObservableAsync<T>, Action<T>?, Action<Exception>?, Action<Result>?)
Invokes the specified actions in response to notifications from the observable sequence without modifying the sequence itself.
public static IObservableAsync<T> Do<T>(this IObservableAsync<T> @this, Action<T>? onNext = null, Action<Exception>? onErrorResume = null, Action<Result>? onCompleted = null)
Parameters
thisIObservableAsync<T>onNextAction<T>An action to invoke for each element in the sequence as it is emitted. If null, no action is taken on element emission.
onErrorResumeAction<Exception>An action to invoke if an error occurs in the sequence. Receives the exception that caused the error. If null, no action is taken on error.
onCompletedAction<Result>An action to invoke when the sequence completes, receiving the final result. If null, no action is taken on completion.
Returns
- IObservableAsync<T>
An observable sequence that is identical to the source sequence but invokes the specified actions for each notification.
Type Parameters
T
Remarks
Use this method to perform side effects such as logging, monitoring, or debugging in response to sequence events without altering the sequence's behavior. The returned observable passes through all elements and notifications unchanged.
Do<T>(IObservableAsync<T>, Func<T, CancellationToken, ValueTask>?, Func<Exception, CancellationToken, ValueTask>?, Func<Result, ValueTask>?)
Invokes the specified asynchronous actions for each element, error, or completion notification in the observable sequence without modifying the sequence.
public static IObservableAsync<T> Do<T>(this IObservableAsync<T> @this, Func<T, CancellationToken, ValueTask>? onNext, Func<Exception, CancellationToken, ValueTask>? onErrorResume = null, Func<Result, ValueTask>? onCompleted = null)
Parameters
thisIObservableAsync<T>onNextFunc<T, CancellationToken, ValueTask>An asynchronous callback to invoke for each element in the sequence. Receives the element and a cancellation token. If null, no action is taken on elements.
onErrorResumeFunc<Exception, CancellationToken, ValueTask>An optional asynchronous callback to invoke if an error occurs in the sequence. Receives the exception and a cancellation token. If null, errors are not handled by this observer.
onCompletedFunc<Result, ValueTask>An optional asynchronous callback to invoke when the sequence completes. Receives the result of the sequence. If null, no action is taken on completion.
Returns
- IObservableAsync<T>
An observable sequence that is identical to the source sequence but invokes the specified callbacks for side effects.
Type Parameters
T
Remarks
Use this method to perform side effects such as logging, resource cleanup, or notification in response to elements, errors, or completion events in the sequence. The callbacks are invoked asynchronously and do not alter the elements or flow of the sequence.
Empty<T>()
Creates an observable sequence that completes immediately without emitting any items.
public static IObservableAsync<T> Empty<T>()
Returns
- IObservableAsync<T>
An observable sequence of type
Tthat completes immediately without producing any values.
Type Parameters
TThe type of elements in the observable sequence.
Remarks
This method is useful for representing an empty sequence in asynchronous or reactive scenarios. The returned sequence signals completion to observers as soon as it is subscribed to.
FirstAsync<T>(IObservableAsync<T>, Func<T, bool>, CancellationToken)
Asynchronously returns the first element in the sequence that satisfies the specified predicate.
public static ValueTask<T> FirstAsync<T>(this IObservableAsync<T> @this, Func<T, bool> predicate, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>predicateFunc<T, bool>A function to test each element for a condition. The method returns the first element for which this predicate returns true.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<T>
A task that represents the asynchronous operation. The task result contains the first element that matches the predicate.
Type Parameters
T
FirstAsync<T>(IObservableAsync<T>, CancellationToken)
Asynchronously returns the first element of the sequence.
public static ValueTask<T> FirstAsync<T>(this IObservableAsync<T> @this, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<T>
A task that represents the asynchronous operation. The task result contains the first element of the sequence.
Type Parameters
T
Remarks
If the sequence is empty, the behavior depends on the implementation and may result in an exception being thrown.
FirstOrDefaultAsync<T>(IObservableAsync<T>, Func<T, bool>, T?, CancellationToken)
Asynchronously returns the first element that matches the specified predicate, or a default value if no such element is found.
public static ValueTask<T?> FirstOrDefaultAsync<T>(this IObservableAsync<T> @this, Func<T, bool> predicate, T? defaultValue, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>predicateFunc<T, bool>A function to test each element for a condition. The method returns the first element for which this predicate returns true.
defaultValueTThe value to return if no element satisfies the predicate.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<T>
A value task that represents the asynchronous operation. The result contains the first element that matches the predicate, or
defaultValueif no such element is found.
Type Parameters
T
FirstOrDefaultAsync<T>(IObservableAsync<T>, CancellationToken)
Asynchronously returns the first element of the sequence, or a default value if the sequence contains no elements.
public static ValueTask<T?> FirstOrDefaultAsync<T>(this IObservableAsync<T> @this, CancellationToken cancellationToken = default) where T : notnull
Parameters
thisIObservableAsync<T>cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<T>
A value task that represents the asynchronous operation. The task result contains the first element of the sequence, or the default value for type T if the sequence is empty.
Type Parameters
T
FirstOrDefaultAsync<T>(IObservableAsync<T>, T?, CancellationToken)
Asynchronously returns the first element of the sequence, or a specified default value if the sequence contains no elements.
public static ValueTask<T?> FirstOrDefaultAsync<T>(this IObservableAsync<T> @this, T? defaultValue, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>defaultValueTThe value to return if the sequence is empty.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<T>
A task that represents the asynchronous operation. The task result contains the first element of the sequence, or
defaultValueif the sequence is empty.
Type Parameters
T
ForEachAsync<T>(IObservableAsync<T>, Action<T>, CancellationToken)
Asynchronously invokes the specified action for each element in the sequence as elements are received.
public static ValueTask ForEachAsync<T>(this IObservableAsync<T> @this, Action<T> onNext, CancellationToken cancellationToken = default) where T : notnull
Parameters
thisIObservableAsync<T>onNextAction<T>The action to invoke for each element in the sequence. Cannot be null.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the iteration.
Returns
- ValueTask
A task that represents the asynchronous iteration operation. The task completes when the sequence has been fully processed or the operation is canceled.
Type Parameters
T
Exceptions
- ArgumentNullException
Thrown if
onNextis null.
ForEachAsync<T>(IObservableAsync<T>, Func<T, CancellationToken, ValueTask>, CancellationToken)
Asynchronously invokes the specified action for each element in the sequence as elements are received.
public static ValueTask ForEachAsync<T>(this IObservableAsync<T> @this, Func<T, CancellationToken, ValueTask> onNextAsync, CancellationToken cancellationToken = default) where T : notnull
Parameters
thisIObservableAsync<T>onNextAsyncFunc<T, CancellationToken, ValueTask>A function to invoke for each element in the sequence. The function receives the element and a cancellation token, and returns a ValueTask that completes when processing is finished.
cancellationTokenCancellationTokenA token to observe while waiting for the sequence to complete. The operation is canceled if the token is signaled.
Returns
- ValueTask
A ValueTask that represents the asynchronous operation. The task completes when all elements have been processed or the operation is canceled.
Type Parameters
T
Remarks
If the sequence completes or is canceled, the method returns when all in-flight actions have finished. Exceptions thrown by the action or during enumeration will propagate to the returned task.
FromAsync(Func<CancellationToken, ValueTask>)
Creates an asynchronous observable sequence that executes the specified factory function and signals completion when the operation finishes.
public static IObservableAsync<Unit> FromAsync(Func<CancellationToken, ValueTask> factory)
Parameters
factoryFunc<CancellationToken, ValueTask>A function that performs the asynchronous operation. The function receives a cancellation token that can be used to cancel the operation.
Returns
- IObservableAsync<Unit>
An observable sequence that emits a single value of System.Reactive.Unit when the factory function completes, followed by a completion notification.
Remarks
The returned observable executes the factory function as a background job. The sequence emits System.Reactive.Unit.Default after the factory completes and then signals completion. Cancellation is supported via the provided token.
Exceptions
- ArgumentNullException
Thrown if
factoryis null.
FromAsync<T>(Func<CancellationToken, ValueTask<T>>)
Creates an asynchronous observable sequence that emits a single value produced by the specified factory function.
public static IObservableAsync<T> FromAsync<T>(Func<CancellationToken, ValueTask<T>> factory)
Parameters
factoryFunc<CancellationToken, ValueTask<T>>A function that asynchronously produces a value of type
Twhen invoked with a CancellationToken. Cannot be null.
Returns
- IObservableAsync<T>
An ObservableAsync<T> that emits the value returned by the factory function and then completes.
Type Parameters
TThe type of the value produced by the factory and emitted by the observable sequence.
Remarks
The observable sequence will emit the value produced by the factory and then signal completion. The factory function is invoked when the sequence is subscribed to, and supports cancellation via the provided CancellationToken.
Exceptions
- ArgumentNullException
Thrown if
factoryis null.
GroupBy<TKey, TValue>(IObservableAsync<TValue>, Func<TValue, TKey>)
Groups the elements of an asynchronous observable sequence according to a specified key selector function.
public static IObservableAsync<GroupedAsyncObservable<TKey, TValue>> GroupBy<TKey, TValue>(this IObservableAsync<TValue> source, Func<TValue, TKey> keySelector) where TKey : notnull
Parameters
sourceIObservableAsync<TValue>The asynchronous observable sequence whose elements are to be grouped.
keySelectorFunc<TValue, TKey>A function to extract the key for each element in the source sequence.
Returns
- IObservableAsync<GroupedAsyncObservable<TKey, TValue>>
An asynchronous observable sequence of grouped observables, each containing elements that share a common key.
Type Parameters
TKeyThe type of the key returned by the key selector function. Must be non-nullable.
TValueThe type of the elements in the source observable sequence.
Remarks
Each group in the resulting sequence corresponds to a unique key produced by the key selector. The groups are emitted as soon as their first element is encountered in the source sequence. The returned grouped observables can be subscribed to independently.
Exceptions
- ArgumentNullException
Thrown if
sourceorkeySelectoris null.
GroupBy<TKey, TValue>(IObservableAsync<TValue>, Func<TValue, TKey>, Func<TKey, ISubjectAsync<TValue>>)
Groups the elements of an asynchronous observable sequence according to a specified key selector function and returns an observable sequence of grouped observables.
public static IObservableAsync<GroupedAsyncObservable<TKey, TValue>> GroupBy<TKey, TValue>(this IObservableAsync<TValue> source, Func<TValue, TKey> keySelector, Func<TKey, ISubjectAsync<TValue>> groupSubjectSelector) where TKey : notnull
Parameters
sourceIObservableAsync<TValue>The asynchronous observable sequence whose elements are to be grouped.
keySelectorFunc<TValue, TKey>A function to extract the key for each element in the source sequence.
groupSubjectSelectorFunc<TKey, ISubjectAsync<TValue>>A function that provides a subject for each group, given its key. Used to control how elements are published within each group.
Returns
- IObservableAsync<GroupedAsyncObservable<TKey, TValue>>
An asynchronous observable sequence containing grouped observables, each representing a collection of elements that share a common key.
Type Parameters
TKeyThe type of the key returned by the key selector function. Must be non-null.
TValueThe type of the elements in the source observable sequence.
Remarks
Each group in the resulting sequence is represented by a GroupedAsyncObservable<TKey, TValue>, which exposes the group's key and an observable sequence of its
elements. The groupSubjectSelector parameter allows customization of the subject used for
each group, which can affect how elements are buffered or multicast within the group.
Exceptions
- ArgumentNullException
Thrown if
sourceorkeySelectoris null.
Interval(TimeSpan, TimeProvider?)
Creates an asynchronous observable sequence that emits a long integer value at each specified time interval.
public static IObservableAsync<long> Interval(TimeSpan period, TimeProvider? timeProvider = null)
Parameters
periodTimeSpanThe time interval between emissions of values. Must be a positive duration.
timeProviderTimeProviderAn optional time provider used to control the timing of emissions. If null or set to TimeProvider.System, the system clock is used.
Returns
- IObservableAsync<long>
An ObservableAsync{long} that emits an increasing long value at each interval, starting from 1, until the sequence is cancelled.
Remarks
The sequence continues emitting values until the observer unsubscribes or the cancellation token is triggered. This method is useful for generating periodic events or timers in asynchronous workflows.
LastAsync<T>(IObservableAsync<T>, Func<T, bool>, CancellationToken)
Asynchronously returns the last element in the sequence that satisfies the specified predicate.
public static ValueTask<T> LastAsync<T>(this IObservableAsync<T> @this, Func<T, bool> predicate, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>predicateFunc<T, bool>A function to test each element for a condition. The method returns the last element for which this predicate returns true.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<T>
A task that represents the asynchronous operation. The task result contains the last element that matches the predicate.
Type Parameters
T
LastAsync<T>(IObservableAsync<T>, CancellationToken)
Asynchronously returns the last element of the sequence.
public static ValueTask<T> LastAsync<T>(this IObservableAsync<T> @this, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<T>
A task that represents the asynchronous operation. The task result contains the last element of the sequence.
Type Parameters
T
Remarks
If the sequence is empty, the behavior depends on the implementation and may result in an exception being thrown. The operation is performed asynchronously and may not complete immediately.
LastOrDefaultAsync<T>(IObservableAsync<T>, Func<T, bool>, T?, CancellationToken)
Asynchronously returns the last element in the sequence that satisfies the specified predicate, or a default value if no such element is found.
public static ValueTask<T?> LastOrDefaultAsync<T>(this IObservableAsync<T> @this, Func<T, bool> predicate, T? defaultValue, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>predicateFunc<T, bool>A function to test each element for a condition. The method returns the last element for which this predicate returns true.
defaultValueTThe value to return if no element in the sequence satisfies the predicate.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<T>
A value task that represents the asynchronous operation. The result contains the last element that matches the predicate, or
defaultValueif no such element is found.
Type Parameters
T
LastOrDefaultAsync<T>(IObservableAsync<T>, CancellationToken)
Asynchronously returns the last element of a sequence, or a default value if the sequence contains no elements.
public static ValueTask<T?> LastOrDefaultAsync<T>(this IObservableAsync<T> @this, CancellationToken cancellationToken = default) where T : notnull
Parameters
thisIObservableAsync<T>cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<T>
A value task that represents the asynchronous operation. The task result contains the last element of the sequence, or the default value for type T if the sequence is empty.
Type Parameters
T
LastOrDefaultAsync<T>(IObservableAsync<T>, T?, CancellationToken)
Asynchronously returns the last element of the sequence, or a specified default value if the sequence contains no elements.
public static ValueTask<T?> LastOrDefaultAsync<T>(this IObservableAsync<T> @this, T? defaultValue, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>defaultValueTThe value to return if the sequence is empty.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<T>
A value task that represents the asynchronous operation. The task result contains the last element of the sequence, or
defaultValueif the sequence is empty.
Type Parameters
T
LongCountAsync<T>(IObservableAsync<T>, Func<T, bool>?, CancellationToken)
Asynchronously returns the number of elements in the sequence that satisfy an optional predicate.
public static ValueTask<long> LongCountAsync<T>(this IObservableAsync<T> @this, Func<T, bool>? predicate, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>predicateFunc<T, bool>A function to test each element for a condition. If null, all elements are counted.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<long>
A task that represents the asynchronous operation. The task result contains the number of elements that satisfy the predicate, or the total number of elements if the predicate is null.
Type Parameters
T
LongCountAsync<T>(IObservableAsync<T>, CancellationToken)
Asynchronously returns the total number of elements in the sequence as a 64-bit integer.
public static ValueTask<long> LongCountAsync<T>(this IObservableAsync<T> @this, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<long>
A value task representing the asynchronous operation. The result contains the number of elements in the sequence as a 64-bit integer.
Type Parameters
T
Merge<T>(IObservableAsync<IObservableAsync<T>>)
Merges multiple asynchronous observable sequences into a single observable sequence that emits items from all inner sequences as they arrive.
public static IObservableAsync<T> Merge<T>(this IObservableAsync<IObservableAsync<T>> @this)
Parameters
thisIObservableAsync<IObservableAsync<T>>The source asynchronous observable sequence whose elements are themselves observable sequences to be merged. Cannot be null.
Returns
- IObservableAsync<T>
An asynchronous observable sequence that emits items from all inner observable sequences as they are produced.
Type Parameters
TThe type of the elements emitted by the inner observable sequences.
Remarks
The resulting sequence emits items from all inner sequences concurrently as they become available. The merged sequence completes when the source sequence and all inner sequences have completed. If any inner sequence signals an error, the merged sequence will propagate that error and terminate.
Merge<T>(IObservableAsync<IObservableAsync<T>>, int)
Merges the emissions of multiple asynchronous observable sequences into a single observable sequence, limiting the number of concurrent subscriptions.
public static IObservableAsync<T> Merge<T>(this IObservableAsync<IObservableAsync<T>> @this, int maxConcurrent)
Parameters
thisIObservableAsync<IObservableAsync<T>>The source observable sequence whose elements are themselves observable sequences to be merged.
maxConcurrentintThe maximum number of inner observable sequences to subscribe to concurrently. Must be greater than zero.
Returns
- IObservableAsync<T>
An observable sequence that emits the items from the merged inner observable sequences, with at most the specified number of concurrent subscriptions.
Type Parameters
TThe type of the elements emitted by the inner observable sequences.
Remarks
If the number of active inner subscriptions reaches the specified maximum, additional inner sequences are queued and subscribed to as others complete. The resulting sequence completes when all inner sequences have completed. If the source or any inner observable sequence signals an error, the resulting sequence will propagate that error and terminate.
Merge<T>(IObservableAsync<T>, IObservableAsync<T>)
Combines the elements of two asynchronous observable sequences into a single sequence by merging their emissions.
public static IObservableAsync<T> Merge<T>(this IObservableAsync<T> @this, IObservableAsync<T> other)
Parameters
thisIObservableAsync<T>The first asynchronous observable sequence to merge.
otherIObservableAsync<T>The second asynchronous observable sequence to merge with the first.
Returns
- IObservableAsync<T>
An ObservableAsync{T} that emits the elements from both input sequences as they arrive.
Type Parameters
TThe type of the elements in the observable sequences.
Remarks
The resulting sequence emits items from both source sequences in the order they are produced. The merged sequence completes when both input sequences have completed. If either source sequence signals an error, the merged sequence will propagate that error and terminate.
Merge<T>(IEnumerable<IObservableAsync<T>>)
Combines multiple asynchronous observable sequences into a single observable sequence that emits items from all source sequences as they arrive.
public static IObservableAsync<T> Merge<T>(this IEnumerable<IObservableAsync<T>> @this)
Parameters
thisIEnumerable<IObservableAsync<T>>A collection of asynchronous observable sequences to be merged.
Returns
- IObservableAsync<T>
An observable sequence that emits items from all input sequences as they are produced.
Type Parameters
TThe type of the elements produced by the observable sequences.
Remarks
The resulting observable sequence emits items from all source sequences in the order they arrive, interleaving emissions if sources produce items concurrently. The merged sequence completes when all source sequences have completed. If any source sequence signals an error, the merged sequence will propagate that error and terminate.
Multicast<T>(IObservableAsync<T>, ISubjectAsync<T>)
Creates a connectable observable sequence that shares a single subscription to the underlying sequence using the specified subject.
public static ConnectableObservableAsync<T> Multicast<T>(this IObservableAsync<T> source, ISubjectAsync<T> subject) where T : notnull
Parameters
sourceIObservableAsync<T>subjectISubjectAsync<T>The subject used to multicast the elements of the source sequence to multiple observers. Cannot be null.
Returns
- ConnectableObservableAsync<T>
A connectable observable sequence that multicasts the source sequence through the specified subject.
Type Parameters
T
Remarks
The returned connectable observable will not begin emitting items until its Connect method is called. This allows multiple observers to subscribe before the sequence starts.
Never<T>()
Creates an observable sequence that never produces any values and never completes.
public static IObservableAsync<T> Never<T>()
Returns
- IObservableAsync<T>
An observable sequence of type
Tthat never emits any items and never terminates.
Type Parameters
TThe type of elements in the observable sequence.
Remarks
This method is useful for testing or composing observables where a sequence that remains idle is required. The returned observable will not invoke any callbacks and will not signal completion or error.
ObserveOn<T>(IObservableAsync<T>, AsyncContext, bool)
Wraps the source observable so that observer callbacks are invoked on the specified async context.
public static IObservableAsync<T> ObserveOn<T>(this IObservableAsync<T> @this, AsyncContext asyncContext, bool forceYielding = false) where T : notnull
Parameters
thisIObservableAsync<T>asyncContextAsyncContextThe async context on which observer callbacks should be invoked.
forceYieldingboolWhen true, forces an asynchronous yield before invoking each callback, even if already on the target context.
Returns
- IObservableAsync<T>
An observable sequence whose observer callbacks execute on the specified context.
Type Parameters
T
ObserveOn<T>(IObservableAsync<T>, IScheduler, bool)
Configures the observable sequence to notify observers on the specified scheduler.
public static IObservableAsync<T> ObserveOn<T>(this IObservableAsync<T> @this, IScheduler scheduler, bool forceYielding = false) where T : notnull
Parameters
thisIObservableAsync<T>schedulerISchedulerThe scheduler on which to observe and deliver notifications to observers. Cannot be null.
forceYieldingbooltrue to force yielding to the scheduler even if already on the target context; otherwise, false.
Returns
- IObservableAsync<T>
An observable sequence whose notifications are delivered on the specified scheduler.
Type Parameters
T
Remarks
Use this method to control the context (such as a UI thread or a specific task scheduler) on which observers receive notifications. This is useful for ensuring thread safety or updating UI elements from observable sequences.
ObserveOn<T>(IObservableAsync<T>, SynchronizationContext, bool)
Wraps the source observable so that observer callbacks are invoked on the specified synchronization context.
public static IObservableAsync<T> ObserveOn<T>(this IObservableAsync<T> @this, SynchronizationContext synchronizationContext, bool forceYielding = false) where T : notnull
Parameters
thisIObservableAsync<T>synchronizationContextSynchronizationContextThe synchronization context on which observer callbacks should be posted.
forceYieldingboolWhen true, forces an asynchronous yield before invoking each callback.
Returns
- IObservableAsync<T>
An observable sequence whose observer callbacks execute on the specified synchronization context.
Type Parameters
T
ObserveOn<T>(IObservableAsync<T>, TaskScheduler, bool)
Wraps the source observable so that observer callbacks are invoked using the specified task scheduler.
public static IObservableAsync<T> ObserveOn<T>(this IObservableAsync<T> @this, TaskScheduler taskScheduler, bool forceYielding = false) where T : notnull
Parameters
thisIObservableAsync<T>taskSchedulerTaskSchedulerThe task scheduler on which observer callbacks should be scheduled.
forceYieldingboolWhen true, forces an asynchronous yield before invoking each callback.
Returns
- IObservableAsync<T>
An observable sequence whose observer callbacks execute on the specified task scheduler.
Type Parameters
T
OfType<T, TResult>(IObservableAsync<T>)
Projects each element of the observable sequence to the specified reference type and filters out elements that are not of that type.
public static IObservableAsync<TResult> OfType<T, TResult>(this IObservableAsync<T> @this) where T : notnull where TResult : class
Parameters
thisIObservableAsync<T>
Returns
- IObservableAsync<TResult>
An observable sequence containing only the elements of type TResult from the original sequence.
Type Parameters
TTResultThe reference type to filter and project elements to. Must be a class.
Remarks
Elements that are not of type TResult are ignored and not included in the resulting sequence. This method is useful for working with observable sequences containing heterogeneous types, allowing subscribers to focus on elements of a specific type.
OnDispose<T>(IObservableAsync<T>, Action)
Registers an action to be invoked when the observable sequence is disposed.
public static IObservableAsync<T> OnDispose<T>(this IObservableAsync<T> @this, Action onDispose) where T : notnull
Parameters
thisIObservableAsync<T>onDisposeActionThe action to execute when the subscription is disposed. Cannot be null.
Returns
- IObservableAsync<T>
An observable sequence that invokes the specified action upon disposal of the subscription.
Type Parameters
T
Remarks
Use this method to perform cleanup or resource release logic when a subscription to the observable is disposed. The specified action is called synchronously during disposal. If multiple actions are registered through chained calls, each will be invoked in the order registered.
OnDispose<T>(IObservableAsync<T>, Func<ValueTask>)
Registers a callback to be invoked asynchronously when the observable sequence is disposed.
public static IObservableAsync<T> OnDispose<T>(this IObservableAsync<T> @this, Func<ValueTask> onDispose) where T : notnull
Parameters
thisIObservableAsync<T>onDisposeFunc<ValueTask>A function that returns a ValueTask representing the asynchronous operation to execute upon disposal of the observable sequence. Cannot be null.
Returns
- IObservableAsync<T>
An ObservableAsync{T} that invokes the specified asynchronous callback when disposed.
Type Parameters
T
Remarks
Use this method to perform custom asynchronous cleanup or resource release logic when the observable sequence is disposed. The callback is invoked when the subscription is disposed, either explicitly or when the observer completes or errors.
OnErrorResumeAsFailure<T>(IObservableAsync<T>)
Creates a new observable sequence that converts any error encountered in the source sequence into a failure result, allowing the sequence to complete without propagating exceptions.
public static IObservableAsync<T> OnErrorResumeAsFailure<T>(this IObservableAsync<T> @this)
Parameters
thisIObservableAsync<T>The source asynchronous observable sequence to monitor for errors.
Returns
- IObservableAsync<T>
An observable sequence that emits the same elements as the source, but represents errors as failure results instead of throwing exceptions.
Type Parameters
TThe type of the elements in the observable sequence.
Remarks
This method enables error handling by transforming exceptions into failure notifications within the sequence, rather than terminating the sequence with an error. Consumers can inspect the result to determine whether an operation succeeded or failed.
Prepend<T>(IObservableAsync<T>, IEnumerable<T>)
Returns a new observable sequence that emits the specified values before the emissions from the current sequence.
public static IObservableAsync<T> Prepend<T>(this IObservableAsync<T> @this, IEnumerable<T> values) where T : notnull
Parameters
thisIObservableAsync<T>valuesIEnumerable<T>The collection of values to emit before the original sequence. Cannot be null.
Returns
- IObservableAsync<T>
An observable sequence that emits the specified values first, followed by the items from the current sequence.
Type Parameters
T
Remarks
The values in the provided collection are emitted in order before any items from the original sequence. If the sequence is unsubscribed before completion, remaining values may not be emitted.
Prepend<T>(IObservableAsync<T>, T)
Returns a new observable sequence that begins with the specified value, followed by the elements of the current sequence.
public static IObservableAsync<T> Prepend<T>(this IObservableAsync<T> @this, T value)
Parameters
thisIObservableAsync<T>valueTThe value to prepend to the beginning of the sequence.
Returns
- IObservableAsync<T>
An observable sequence with the specified value prepended to the original sequence.
Type Parameters
T
Publish<T>(IObservableAsync<T>)
Returns a connectable observable sequence that shares a single subscription to the underlying asynchronous observable. Observers will receive all notifications published after they subscribe.
public static ConnectableObservableAsync<T> Publish<T>(this IObservableAsync<T> source) where T : notnull
Parameters
sourceIObservableAsync<T>
Returns
- ConnectableObservableAsync<T>
A connectable observable sequence that multicasts notifications to all subscribed observers. The sequence does not begin emitting items until its Connect method is called.
Type Parameters
T
Remarks
Use this method to create a hot observable that allows multiple observers to share a single subscription to the source. This is useful for scenarios where you want to avoid multiple subscriptions to the source sequence or coordinate the timing of subscriptions. The returned connectable observable is asynchronous and supports concurrent observers.
Publish<T>(IObservableAsync<T>, SubjectCreationOptions)
Creates a connectable observable sequence that shares a single subscription to the underlying sequence, using a subject created with the specified options.
public static ConnectableObservableAsync<T> Publish<T>(this IObservableAsync<T> source, SubjectCreationOptions options) where T : notnull
Parameters
sourceIObservableAsync<T>optionsSubjectCreationOptionsThe options used to configure the subject that will multicast the source sequence. Cannot be null.
Returns
- ConnectableObservableAsync<T>
A connectable observable sequence that multicasts the source sequence using a subject configured with the specified options.
Type Parameters
T
Remarks
The returned connectable observable does not begin emitting items until its Connect method is called. Use this method to control when the subscription to the source sequence starts and to share the subscription among multiple observers.
Publish<T>(IObservableAsync<T>, T)
Returns a connectable observable sequence that shares a single subscription to the underlying sequence and replays the most recent value to new subscribers, starting with the specified initial value.
public static ConnectableObservableAsync<T> Publish<T>(this IObservableAsync<T> source, T initialValue)
Parameters
sourceIObservableAsync<T>initialValueTThe initial value to be emitted to subscribers before any values are emitted by the source sequence.
Returns
- ConnectableObservableAsync<T>
A connectable observable sequence that multicasts the source sequence and replays the latest value, starting with the specified initial value.
Type Parameters
T
Remarks
Subscribers will immediately receive the initial value upon subscription, followed by subsequent values from the source sequence. The returned connectable observable does not begin emitting values until its Connect method is called.
Publish<T>(IObservableAsync<T>, T, BehaviorSubjectCreationOptions)
Creates a connectable observable sequence that shares a single subscription to the underlying sequence and starts with the specified initial value.
public static ConnectableObservableAsync<T> Publish<T>(this IObservableAsync<T> source, T initialValue, BehaviorSubjectCreationOptions options)
Parameters
sourceIObservableAsync<T>initialValueTThe initial value to be emitted to subscribers before any items are emitted by the source sequence.
optionsBehaviorSubjectCreationOptionsThe options used to configure the behavior of the underlying behavior subject.
Returns
- ConnectableObservableAsync<T>
A connectable observable sequence that multicasts the source sequence and emits the specified initial value to new subscribers.
Type Parameters
T
Remarks
The returned connectable observable will not begin emitting items from the source sequence until its Connect method is called. Subscribers will immediately receive the most recent value, starting with the specified initial value, upon subscription.
Range(int, int)
Creates an observable sequence that emits a range of consecutive integer values, starting from the specified value.
public static IObservableAsync<int> Range(int start, int count)
Parameters
startintThe value of the first integer in the sequence.
countintThe number of sequential integers to emit. Must be non-negative.
Returns
- IObservableAsync<int>
An observable sequence that emits integers from
starttostart+count- 1, in order.
Remarks
The sequence completes after emitting all values. If count is zero, the
sequence completes immediately without emitting any values. The operation supports cancellation via the
observer's cancellation token.
RefCount<T>(ConnectableObservableAsync<T>)
Returns an observable sequence that connects to the underlying connectable observable when the first observer subscribes, and disconnects when the last observer unsubscribes.
public static ObservableAsync<T> RefCount<T>(this ConnectableObservableAsync<T> source)
Parameters
sourceConnectableObservableAsync<T>The connectable observable sequence to ref count. Cannot be null.
Returns
- ObservableAsync<T>
An observable sequence that stays connected to the source as long as there is at least one subscription.
Type Parameters
TThe type of the elements in the observable sequence.
Remarks
This operator is useful for sharing a single subscription to the underlying connectable observable among multiple subscribers. When the last observer unsubscribes, the connection to the source is automatically disposed.
ReplayLatestPublish<T>(IObservableAsync<T>)
Creates a connectable observable sequence that replays only the most recent item to new subscribers.
public static ConnectableObservableAsync<T> ReplayLatestPublish<T>(this IObservableAsync<T> source) where T : notnull
Parameters
sourceIObservableAsync<T>
Returns
- ConnectableObservableAsync<T>
A connectable observable sequence that publishes the latest item to current and future subscribers until a new item is emitted.
Type Parameters
T
Remarks
This method enables late subscribers to immediately receive the most recently published value, followed by subsequent values. The returned sequence does not replay earlier items beyond the latest one. Use this method when you want all subscribers to observe the most recent value, regardless of when they subscribe.
ReplayLatestPublish<T>(IObservableAsync<T>, ReplayLatestSubjectCreationOptions)
Creates a connectable observable sequence that replays only the latest published value to new subscribers, using the specified replay subject creation options.
public static ConnectableObservableAsync<T> ReplayLatestPublish<T>(this IObservableAsync<T> source, ReplayLatestSubjectCreationOptions options) where T : notnull
Parameters
sourceIObservableAsync<T>optionsReplayLatestSubjectCreationOptionsThe options used to configure the replay subject, such as buffer size, scheduler, or other replay behavior settings.
Returns
- ConnectableObservableAsync<T>
A connectable observable sequence that replays the most recent value to each new subscriber after connection.
Type Parameters
T
Remarks
Use this method when you want late subscribers to receive only the most recently published value, rather than the entire sequence or a fixed buffer. The returned connectable observable does not begin emitting items until its Connect method is called.
Retry<T>(IObservableAsync<T>)
Repeats the source observable sequence indefinitely until it completes successfully, re-subscribing on each error.
public static IObservableAsync<T> Retry<T>(this IObservableAsync<T> @this) where T : notnull
Parameters
thisIObservableAsync<T>
Returns
- IObservableAsync<T>
An observable sequence that mirrors the source and re-subscribes on error until a successful completion occurs.
Type Parameters
T
Retry<T>(IObservableAsync<T>, int)
Repeats the source observable sequence on error up to the specified number of times.
public static IObservableAsync<T> Retry<T>(this IObservableAsync<T> @this, int retryCount) where T : notnull
Parameters
thisIObservableAsync<T>retryCountintThe maximum number of times to re-subscribe to the source on error. Must be greater than or equal to zero. A value of 0 means no retries (original sequence only).
Returns
- IObservableAsync<T>
An observable sequence that mirrors the source, re-subscribing on error up to the specified number of times. If all retries are exhausted, the last error is propagated.
Type Parameters
T
Exceptions
- ArgumentOutOfRangeException
Thrown if
retryCountis negative.
Return<T>(T)
Creates an observable sequence that emits a single value and then completes.
public static IObservableAsync<T> Return<T>(T value)
Parameters
valueTThe value to be emitted by the observable sequence.
Returns
- IObservableAsync<T>
An observable sequence that emits the specified value and then signals completion.
Type Parameters
TThe type of the value to be emitted by the observable sequence.
Remarks
The returned observable sequence emits the value asynchronously and completes immediately after. This method is useful for creating simple observable sequences for testing or composing with other observables.
Scan<T, TAcc>(IObservableAsync<T>, TAcc, Func<TAcc, T, CancellationToken, ValueTask<TAcc>>)
Applies an accumulator function over the observable sequence and returns each intermediate result using the specified asynchronous accumulator.
public static IObservableAsync<TAcc> Scan<T, TAcc>(this IObservableAsync<T> @this, TAcc seed, Func<TAcc, T, CancellationToken, ValueTask<TAcc>> accumulator)
Parameters
thisIObservableAsync<T>seedTAccThe initial accumulator value.
accumulatorFunc<TAcc, T, CancellationToken, ValueTask<TAcc>>An asynchronous accumulator function to be invoked on each element. Receives the current accumulator value, the current element, and a cancellation token.
Returns
- IObservableAsync<TAcc>
An observable sequence containing the accumulated values produced after each element is processed.
Type Parameters
TTAccThe type of the accumulated value.
Exceptions
- ArgumentNullException
Thrown if
accumulatoris null.
Scan<T, TAcc>(IObservableAsync<T>, TAcc, Func<TAcc, T, TAcc>)
Applies an accumulator function over the observable sequence and returns each intermediate result.
public static IObservableAsync<TAcc> Scan<T, TAcc>(this IObservableAsync<T> @this, TAcc seed, Func<TAcc, T, TAcc> accumulator)
Parameters
thisIObservableAsync<T>seedTAccThe initial accumulator value.
accumulatorFunc<TAcc, T, TAcc>An accumulator function to be invoked on each element. Receives the current accumulator value and the current element.
Returns
- IObservableAsync<TAcc>
An observable sequence containing the accumulated values produced after each element is processed.
Type Parameters
TTAccThe type of the accumulated value.
Exceptions
- ArgumentNullException
Thrown if
accumulatoris null.
SelectMany<T, TResult>(IObservableAsync<T>, Func<T, IObservableAsync<TResult>>)
Projects each element of the observable sequence to an asynchronous observable sequence and merges the resulting sequences into one observable sequence.
public static IObservableAsync<TResult> SelectMany<T, TResult>(this IObservableAsync<T> @this, Func<T, IObservableAsync<TResult>> selector) where T : notnull where TResult : notnull
Parameters
thisIObservableAsync<T>selectorFunc<T, IObservableAsync<TResult>>A transform function to apply to each element; it returns an observable sequence for each element.
Returns
- IObservableAsync<TResult>
An observable sequence whose elements are the result of invoking the one-to-many transform function on each element of the source sequence and merging the results.
Type Parameters
TTResultThe type of the elements in the projected inner sequences.
Exceptions
- ArgumentNullException
Thrown if
selectoris null.
SelectMany<T, TResult>(IObservableAsync<T>, Func<T, CancellationToken, ValueTask<IObservableAsync<TResult>>>)
Projects each element of the observable sequence to an asynchronous observable sequence using an asynchronous selector and merges the resulting sequences into one observable sequence.
public static IObservableAsync<TResult> SelectMany<T, TResult>(this IObservableAsync<T> @this, Func<T, CancellationToken, ValueTask<IObservableAsync<TResult>>> selector) where T : notnull where TResult : notnull
Parameters
thisIObservableAsync<T>selectorFunc<T, CancellationToken, ValueTask<IObservableAsync<TResult>>>An asynchronous transform function to apply to each element; it returns an observable sequence for each element.
Returns
- IObservableAsync<TResult>
An observable sequence whose elements are the result of invoking the one-to-many transform function on each element of the source sequence and merging the results.
Type Parameters
TTResultThe type of the elements in the projected inner sequences.
Exceptions
- ArgumentNullException
Thrown if
selectoris null.
SelectMany<T, TCollection, TResult>(IObservableAsync<T>, Func<T, IObservableAsync<TCollection>>, Func<T, TCollection, TResult>)
Projects each element of the observable sequence to an asynchronous observable sequence, merges the resulting sequences, and applies a result selector to each pair of source and inner element.
public static IObservableAsync<TResult> SelectMany<T, TCollection, TResult>(this IObservableAsync<T> @this, Func<T, IObservableAsync<TCollection>> collectionSelector, Func<T, TCollection, TResult> resultSelector) where T : notnull where TCollection : notnull where TResult : notnull
Parameters
thisIObservableAsync<T>collectionSelectorFunc<T, IObservableAsync<TCollection>>A transform function to apply to each element to produce an intermediate observable sequence.
resultSelectorFunc<T, TCollection, TResult>A transform function to apply to each pair of source element and collection element.
Returns
- IObservableAsync<TResult>
An observable sequence whose elements are the result of invoking the one-to-many transform function on each element of the source sequence, and then mapping each pair of source and collection element through the result selector.
Type Parameters
TTCollectionThe type of the elements in the intermediate inner sequences.
TResultThe type of the elements in the result sequence.
Exceptions
- ArgumentNullException
Thrown if
collectionSelectororresultSelectoris null.
Select<T, TDest>(IObservableAsync<T>, Func<T, CancellationToken, ValueTask<TDest>>)
Projects each element of the observable sequence into a new form using the specified asynchronous selector function.
public static IObservableAsync<TDest> Select<T, TDest>(this IObservableAsync<T> @this, Func<T, CancellationToken, ValueTask<TDest>> selector) where T : notnull where TDest : notnull
Parameters
thisIObservableAsync<T>selectorFunc<T, CancellationToken, ValueTask<TDest>>A function that transforms each element of the source sequence into a value of type
TDestasynchronously. The function receives the source element and a cancellation token.
Returns
- IObservableAsync<TDest>
An observable sequence of type
TDestcontaining the results of applying the selector function to each element of the source sequence.
Type Parameters
TTDestThe type of the value returned by the selector function and produced by the resulting observable sequence.
Remarks
The selector function is invoked for each element as it is observed. If the selector function throws an exception or returns a faulted task, the error is propagated to the observer. The operation supports cancellation via the provided cancellation token.
Select<T, TDest>(IObservableAsync<T>, Func<T, TDest>)
Projects each element of the observable sequence into a new form using the specified selector function.
public static IObservableAsync<TDest> Select<T, TDest>(this IObservableAsync<T> @this, Func<T, TDest> selector) where T : notnull where TDest : notnull
Parameters
thisIObservableAsync<T>selectorFunc<T, TDest>A function that transforms each element of the source sequence into a new value. Cannot be null.
Returns
- IObservableAsync<TDest>
An observable sequence whose elements are the result of invoking the selector function on each element of the source sequence.
Type Parameters
TTDestThe type of the value returned by the selector function.
Remarks
The selector function is applied to each element as it is observed. If the selector throws an exception, the error is propagated to the observer. This method does not modify the source sequence; it produces a new sequence with transformed elements.
SingleAsync<T>(IObservableAsync<T>, Func<T, bool>, CancellationToken)
Asynchronously returns the single element of a sequence that satisfies a specified condition, or throws an exception if more than one such element exists.
public static ValueTask<T> SingleAsync<T>(this IObservableAsync<T> @this, Func<T, bool> predicate, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>predicateFunc<T, bool>A function to test each element for a condition. The method returns the element for which this predicate returns true.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<T>
A task that represents the asynchronous operation. The task result contains the single element that matches the predicate.
Type Parameters
T
Remarks
If no element satisfies the condition, or if more than one element satisfies the condition, an exception is thrown. Use this method when exactly one element is expected to match the predicate.
SingleAsync<T>(IObservableAsync<T>, CancellationToken)
Asynchronously returns the single element of the sequence, and throws an exception if the sequence does not contain exactly one element.
public static ValueTask<T> SingleAsync<T>(this IObservableAsync<T> @this, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<T>
A task that represents the asynchronous operation. The task result contains the single element of the sequence.
Type Parameters
T
Remarks
Use this method when you expect the sequence to contain exactly one element. If the sequence is empty or contains more than one element, an exception is thrown.
SingleOrDefaultAsync<T>(IObservableAsync<T>, Func<T, bool>, T?, CancellationToken)
Asynchronously returns the only element of a sequence that satisfies a specified condition, or a default value if no such element exists; this operation throws if more than one matching element is found.
public static ValueTask<T?> SingleOrDefaultAsync<T>(this IObservableAsync<T> @this, Func<T, bool> predicate, T? defaultValue, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>predicateFunc<T, bool>A function to test each element for a condition. The method returns the element for which this predicate returns true.
defaultValueTThe value to return if no element in the sequence satisfies the condition specified by
predicate.cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<T>
A value task that represents the asynchronous operation. The result contains the single element that matches the predicate, the specified default value if no such element is found, or throws an exception if more than one matching element exists.
Type Parameters
T
Remarks
If more than one element satisfies the condition, an exception is thrown. If no elements satisfy the condition, the specified default value is returned. The operation observes the provided cancellation token.
SingleOrDefaultAsync<T>(IObservableAsync<T>, CancellationToken)
Asynchronously returns the only element of a sequence, or a default value if the sequence is empty; this operation throws an exception if more than one element is found.
public static ValueTask<T?> SingleOrDefaultAsync<T>(this IObservableAsync<T> @this, CancellationToken cancellationToken = default) where T : notnull
Parameters
thisIObservableAsync<T>cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<T>
A value task that represents the asynchronous operation. The task result contains the single element of the sequence, or the default value of
Tif the sequence is empty.
Type Parameters
T
SingleOrDefaultAsync<T>(IObservableAsync<T>, T?, CancellationToken)
Asynchronously returns the single element of the sequence, or a specified default value if the sequence is empty. Throws an exception if the sequence contains more than one element.
public static ValueTask<T?> SingleOrDefaultAsync<T>(this IObservableAsync<T> @this, T? defaultValue, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>defaultValueTThe value to return if the sequence contains no elements.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<T>
A task that represents the asynchronous operation. The task result contains the single element of the sequence, the specified default value if the sequence is empty, or throws if more than one element is present.
Type Parameters
T
Remarks
Use this method when you expect the sequence to contain zero or one element. If the sequence contains more than one element, an exception is thrown. If the sequence is empty, the specified default value is returned.
SkipWhile<T>(IObservableAsync<T>, Func<T, bool>)
Bypasses elements in the observable sequence as long as the specified condition is true, then emits all remaining elements.
public static IObservableAsync<T> SkipWhile<T>(this IObservableAsync<T> @this, Func<T, bool> predicate) where T : notnull
Parameters
thisIObservableAsync<T>predicateFunc<T, bool>A function to test each element for a condition.
Returns
- IObservableAsync<T>
An observable sequence that skips elements while the predicate returns true and emits all subsequent elements.
Type Parameters
T
Exceptions
- ArgumentNullException
Thrown if
predicateis null.
SkipWhile<T>(IObservableAsync<T>, Func<T, CancellationToken, ValueTask<bool>>)
Bypasses elements in the observable sequence as long as the specified asynchronous condition is true, then emits all remaining elements.
public static IObservableAsync<T> SkipWhile<T>(this IObservableAsync<T> @this, Func<T, CancellationToken, ValueTask<bool>> predicate) where T : notnull
Parameters
thisIObservableAsync<T>predicateFunc<T, CancellationToken, ValueTask<bool>>An asynchronous function to test each element for a condition. Receives the element and a cancellation token.
Returns
- IObservableAsync<T>
An observable sequence that skips elements while the predicate returns true and emits all subsequent elements.
Type Parameters
T
Exceptions
- ArgumentNullException
Thrown if
predicateis null.
Skip<T>(IObservableAsync<T>, int)
Returns a new observable sequence that skips the specified number of elements from the start of the source sequence.
public static IObservableAsync<T> Skip<T>(this IObservableAsync<T> @this, int count) where T : notnull
Parameters
thisIObservableAsync<T>countintThe number of elements to skip. Must be greater than or equal to 0.
Returns
- IObservableAsync<T>
An observable sequence that contains the elements of the source sequence after the specified number of elements have been skipped. If the count is 0, the original sequence is returned.
Type Parameters
T
Exceptions
- ArgumentOutOfRangeException
Thrown if count is less than 0.
StartWith<T>(IObservableAsync<T>, IEnumerable<T>)
Prepends the specified values to the beginning of the observable sequence.
public static IObservableAsync<T> StartWith<T>(this IObservableAsync<T> @this, IEnumerable<T> values) where T : notnull
Parameters
thisIObservableAsync<T>valuesIEnumerable<T>The values to prepend to the sequence. Cannot be null.
Returns
- IObservableAsync<T>
An observable sequence that emits the specified values first, followed by the elements of the source sequence.
Type Parameters
T
Remarks
This is equivalent to Prepend(IEnumerable{T}) and follows the System.Reactive naming convention. Values are emitted in the order they appear in the collection.
StartWith<T>(IObservableAsync<T>, T)
Prepends the specified value to the beginning of the observable sequence.
public static IObservableAsync<T> StartWith<T>(this IObservableAsync<T> @this, T value)
Parameters
thisIObservableAsync<T>valueTThe value to prepend to the sequence.
Returns
- IObservableAsync<T>
An observable sequence that emits the specified value first, followed by the elements of the source sequence.
Type Parameters
T
Remarks
This is equivalent to Prepend(T) and follows the System.Reactive naming convention.
StartWith<T>(IObservableAsync<T>, params T[])
Prepends the specified values to the beginning of the observable sequence.
public static IObservableAsync<T> StartWith<T>(this IObservableAsync<T> @this, params T[] values) where T : notnull
Parameters
thisIObservableAsync<T>valuesT[]The values to prepend to the sequence.
Returns
- IObservableAsync<T>
An observable sequence that emits the specified values first, followed by the elements of the source sequence.
Type Parameters
T
Remarks
This overload accepts a params array for convenience. Values are emitted in the order they appear in the array.
StatelessPublish<T>(IObservableAsync<T>)
Creates a connectable observable sequence that shares a single subscription to the underlying source and does not retain any state between subscriptions.
public static ConnectableObservableAsync<T> StatelessPublish<T>(this IObservableAsync<T> source) where T : notnull
Parameters
sourceIObservableAsync<T>
Returns
- ConnectableObservableAsync<T>
A connectable observable sequence that multicasts notifications from the source without retaining state between subscribers.
Type Parameters
T
Remarks
Use this method when you want to share a single subscription to the source among multiple observers, but do not require the observable to cache or replay any items for new subscribers. Each connection to the returned observable is independent and does not affect subsequent connections.
StatelessPublish<T>(IObservableAsync<T>, T)
Creates a connectable observable sequence that shares a single subscription to the underlying source and replays the most recent value to new subscribers, starting with the specified initial value.
public static ConnectableObservableAsync<T> StatelessPublish<T>(this IObservableAsync<T> source, T initialValue)
Parameters
sourceIObservableAsync<T>initialValueTThe initial value to be emitted to subscribers before any values are published by the source sequence.
Returns
- ConnectableObservableAsync<T>
A connectable observable sequence that multicasts the source sequence and replays the latest value, starting with the specified initial value.
Type Parameters
T
Remarks
The returned observable does not maintain any state between connections. Each connection starts with the provided initial value and only replays the most recent value published during that connection. This is useful for scenarios where late subscribers should always receive the latest value, even if they subscribe after the source has started emitting.
StatelessReplayLatestPublish<T>(IObservableAsync<T>)
Creates a connectable observable sequence that replays only the latest item to new subscribers and publishes items to all current subscribers.
public static ConnectableObservableAsync<T> StatelessReplayLatestPublish<T>(this IObservableAsync<T> source) where T : notnull
Parameters
sourceIObservableAsync<T>
Returns
- ConnectableObservableAsync<T>
A connectable observable sequence that replays the most recent item to new subscribers and multicasts notifications to all current subscribers.
Type Parameters
T
Remarks
This method is stateless; each call returns a new connectable observable. Subscribers that connect after an item has been published will immediately receive the latest item. This is useful for scenarios where late subscribers should catch up with the most recent value without receiving the full history.
SubscribeAsync<T>(IObservableAsync<T>)
Subscribes to the source without handling any items asynchronously.
public static ValueTask<IAsyncDisposable> SubscribeAsync<T>(this IObservableAsync<T> source) where T : notnull
Parameters
sourceIObservableAsync<T>
Returns
- ValueTask<IAsyncDisposable>
A value task that represents the asynchronous subscription operation. The result is an IAsyncDisposable that can be disposed to unsubscribe.
Type Parameters
T
SubscribeAsync<T>(IObservableAsync<T>, Action<T>, Action<Exception>?, Action<Result>?, CancellationToken)
Subscribes to the observable sequence asynchronously, invoking the specified callbacks for each element, error, or completion notification.
public static ValueTask<IAsyncDisposable> SubscribeAsync<T>(this IObservableAsync<T> source, Action<T> onNext, Action<Exception>? onErrorResume = null, Action<Result>? onCompleted = null, CancellationToken cancellationToken = default)
Parameters
sourceIObservableAsync<T>onNextAction<T>An action to invoke for each element in the sequence. Cannot be null.
onErrorResumeAction<Exception>An optional action to invoke if an error occurs during the sequence. If null, errors are not handled by the subscriber.
onCompletedAction<Result>An optional action to invoke when the sequence completes. If null, completion is not handled by the subscriber.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the subscription.
Returns
- ValueTask<IAsyncDisposable>
A value task that represents the asynchronous subscription operation. The result is an IAsyncDisposable that can be disposed to unsubscribe from the sequence.
Type Parameters
T
Remarks
The returned IAsyncDisposable should be disposed when the subscription is no longer needed to release resources and stop receiving notifications. This method enables asynchronous, push-based event handling for observable sequences.
Exceptions
- ArgumentNullException
Thrown if
onNextis null, or if the underlying source is null.
SubscribeAsync<T>(IObservableAsync<T>, Action<T>, CancellationToken)
Subscribes to the observable sequence and invokes the specified action for each element received.
public static ValueTask<IAsyncDisposable> SubscribeAsync<T>(this IObservableAsync<T> source, Action<T> onNext, CancellationToken cancellationToken = default) where T : notnull
Parameters
sourceIObservableAsync<T>onNextAction<T>An action to invoke for each element in the sequence. Cannot be null.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the subscription operation.
Returns
- ValueTask<IAsyncDisposable>
A value task that represents the asynchronous subscription operation. The result contains an IAsyncDisposable that can be disposed to unsubscribe from the sequence.
Type Parameters
T
Exceptions
- ArgumentNullException
Thrown if
onNextis null.
SubscribeAsync<T>(IObservableAsync<T>, Func<T, CancellationToken, ValueTask>)
Subscribes asynchronously to receive notifications for each item published by the source.
public static ValueTask<IAsyncDisposable> SubscribeAsync<T>(this IObservableAsync<T> source, Func<T, CancellationToken, ValueTask> onNextAsync) where T : notnull
Parameters
sourceIObservableAsync<T>onNextAsyncFunc<T, CancellationToken, ValueTask>A delegate that is invoked asynchronously for each item published. The delegate receives the item and a cancellation token, and returns a ValueTask that completes when processing is finished. Cannot be null.
Returns
- ValueTask<IAsyncDisposable>
A ValueTask that represents the asynchronous subscription operation. The result contains an IAsyncDisposable that can be disposed to unsubscribe from the source.
Type Parameters
T
SubscribeAsync<T>(IObservableAsync<T>, Func<T, CancellationToken, ValueTask>, Func<Exception, CancellationToken, ValueTask>?, Func<Result, ValueTask>?, CancellationToken)
Subscribes to the asynchronous data source and invokes the specified callbacks for each item, error, or completion notification.
public static ValueTask<IAsyncDisposable> SubscribeAsync<T>(this IObservableAsync<T> source, Func<T, CancellationToken, ValueTask> onNextAsync, Func<Exception, CancellationToken, ValueTask>? onErrorResumeAsync, Func<Result, ValueTask>? onCompletedAsync = null, CancellationToken cancellationToken = default)
Parameters
sourceIObservableAsync<T>onNextAsyncFunc<T, CancellationToken, ValueTask>A delegate that is invoked asynchronously for each item received from the data source. The delegate receives the item and a cancellation token.
onErrorResumeAsyncFunc<Exception, CancellationToken, ValueTask>An optional delegate that is invoked asynchronously if an error occurs during data processing. The delegate receives the exception and a cancellation token. If null, errors are not handled by the subscriber.
onCompletedAsyncFunc<Result, ValueTask>An optional delegate that is invoked asynchronously when the data source completes successfully. The delegate receives a result indicating the completion status. If null, no action is taken on completion.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the subscription and any in-progress callbacks.
Returns
- ValueTask<IAsyncDisposable>
A value task that represents the asynchronous operation. The result is an IAsyncDisposable that can be disposed to unsubscribe from the data source.
Type Parameters
T
Remarks
The returned IAsyncDisposable should be disposed when the subscription is no longer needed to release resources and stop receiving notifications. Callbacks may be invoked concurrently; implement thread safety in the provided delegates if required.
Exceptions
- ArgumentNullException
Thrown if the underlying data source is null.
SubscribeAsync<T>(IObservableAsync<T>, Func<T, CancellationToken, ValueTask>, CancellationToken)
Subscribes asynchronously to receive notifications for each item in the sequence using the specified asynchronous callback.
public static ValueTask<IAsyncDisposable> SubscribeAsync<T>(this IObservableAsync<T> source, Func<T, CancellationToken, ValueTask> onNextAsync, CancellationToken cancellationToken) where T : notnull
Parameters
sourceIObservableAsync<T>onNextAsyncFunc<T, CancellationToken, ValueTask>A function to invoke asynchronously for each item in the sequence. The function receives the item and a cancellation token, and returns a ValueTask that completes when processing is finished.
cancellationTokenCancellationTokenA token that can be used to cancel the subscription operation.
Returns
- ValueTask<IAsyncDisposable>
A ValueTask that represents the asynchronous subscription operation. The result is an IAsyncDisposable that can be disposed to unsubscribe from the sequence.
Type Parameters
T
Exceptions
- ArgumentNullException
Thrown if the underlying source is null.
Switch<T>(IObservableAsync<IObservableAsync<T>>)
Transforms an observable sequence of observable sequences into a single observable sequence that emits values from the most recent inner observable sequence.
public static IObservableAsync<T> Switch<T>(this IObservableAsync<IObservableAsync<T>> @this) where T : notnull
Parameters
thisIObservableAsync<IObservableAsync<T>>
Returns
- IObservableAsync<T>
An observable sequence that emits items from the most recently emitted inner observable sequence. When a new inner sequence is emitted, the previous one is unsubscribed.
Type Parameters
T
Remarks
This operator is commonly used to switch to a new data stream whenever a new inner observable is produced, unsubscribing from the previous inner observable. Only items from the latest inner observable are emitted to subscribers.
TakeUntil<T>(IObservableAsync<T>, CompletionObservableDelegate, TakeUntilOptions?)
Returns an observable sequence that emits items from the source sequence until the specified stop signal completes.
public static IObservableAsync<T> TakeUntil<T>(this IObservableAsync<T> source, CompletionObservableDelegate stopSignalSignal, TakeUntilOptions? options = null) where T : notnull
Parameters
sourceIObservableAsync<T>stopSignalSignalCompletionObservableDelegateA delegate that provides a completion signal. The returned observable will stop emitting items when this signal completes.
optionsTakeUntilOptionsAn optional set of options that configure the behavior of the take-until operation. If null, default options are used.
Returns
- IObservableAsync<T>
An observable sequence that emits items from the source until the stop signal completes.
Type Parameters
T
Exceptions
- ArgumentNullException
Thrown if
stopSignalSignalis null.
TakeUntil<T>(IObservableAsync<T>, Func<T, bool>)
Returns a sequence that emits elements from the source until the specified predicate returns true for an element.
public static IObservableAsync<T> TakeUntil<T>(this IObservableAsync<T> source, Func<T, bool> predicate) where T : notnull
Parameters
sourceIObservableAsync<T>predicateFunc<T, bool>A function to test each element for a condition. The sequence will stop emitting elements when this function returns true.
Returns
- IObservableAsync<T>
An observable sequence that contains the elements from the source sequence up to, but not including, the first element for which the predicate returns true.
Type Parameters
T
Remarks
The element that causes the predicate to return true is not included in the resulting sequence. Subsequent elements from the source are not emitted.
Exceptions
- ArgumentNullException
Thrown if
predicateis null.
TakeUntil<T>(IObservableAsync<T>, Func<T, CancellationToken, ValueTask<bool>>)
Returns an observable sequence that emits elements from the source sequence until the specified asynchronous predicate returns true for an element.
public static IObservableAsync<T> TakeUntil<T>(this IObservableAsync<T> source, Func<T, CancellationToken, ValueTask<bool>> asyncPredicate) where T : notnull
Parameters
sourceIObservableAsync<T>asyncPredicateFunc<T, CancellationToken, ValueTask<bool>>A function that evaluates each element and its associated cancellation token asynchronously. The sequence stops emitting elements when this function returns true.
Returns
- IObservableAsync<T>
An observable sequence that contains the elements from the source sequence up to, but not including, the first element for which the asynchronous predicate returns true.
Type Parameters
T
Exceptions
- ArgumentNullException
Thrown if
asyncPredicateis null.
TakeUntil<T>(IObservableAsync<T>, CancellationToken)
Returns an observable sequence that emits items from the source sequence until the specified cancellation token is canceled.
public static IObservableAsync<T> TakeUntil<T>(this IObservableAsync<T> source, CancellationToken cancellationToken) where T : notnull
Parameters
sourceIObservableAsync<T>cancellationTokenCancellationTokenA cancellation token that, when canceled, will terminate the resulting observable sequence.
Returns
- IObservableAsync<T>
An observable sequence that completes when the provided cancellation token is canceled or when the source sequence completes.
Type Parameters
T
Remarks
If the cancellation token is already canceled when the method is called, the resulting observable sequence will complete immediately.
TakeUntil<T>(IObservableAsync<T>, Task, TakeUntilOptions?)
Returns an observable sequence that emits items from the source until the specified task completes.
public static IObservableAsync<T> TakeUntil<T>(this IObservableAsync<T> source, Task task, TakeUntilOptions? options = null) where T : notnull
Parameters
sourceIObservableAsync<T>taskTaskThe task whose completion will signal the termination of the observable sequence. The sequence will stop emitting items when this task completes, regardless of its result.
optionsTakeUntilOptionsAn optional set of options that control the behavior of the take-until operation. If null, default options are used.
Returns
- IObservableAsync<T>
An observable sequence that emits items from the source until the specified task completes.
Type Parameters
T
Exceptions
- ArgumentNullException
Thrown if the source observable is null.
TakeUntil<T, TOther>(IObservableAsync<T>, IObservableAsync<TOther>, TakeUntilOptions?)
Returns an observable sequence that emits items from the source sequence until the specified other observable emits an item or completes.
public static IObservableAsync<T> TakeUntil<T, TOther>(this IObservableAsync<T> source, IObservableAsync<TOther> other, TakeUntilOptions? options = null)
Parameters
sourceIObservableAsync<T>otherIObservableAsync<TOther>The observable sequence whose first emission or completion will cause the returned sequence to stop emitting items from the source.
optionsTakeUntilOptionsAn optional set of options that control the behavior of the take-until operation. If null, default options are used.
Returns
- IObservableAsync<T>
An observable sequence that emits items from the source sequence until the other observable emits an item or completes.
Type Parameters
TTOtherThe type of the elements in the other observable sequence that triggers termination of the source sequence.
Exceptions
- ArgumentNullException
Thrown if either the source sequence or the other observable is null.
TakeWhile<T>(IObservableAsync<T>, Func<T, bool>)
Returns elements from the observable sequence as long as the specified condition is true, then completes.
public static IObservableAsync<T> TakeWhile<T>(this IObservableAsync<T> @this, Func<T, bool> predicate) where T : notnull
Parameters
thisIObservableAsync<T>predicateFunc<T, bool>A function to test each element for a condition.
Returns
- IObservableAsync<T>
An observable sequence that contains elements from the source sequence that satisfy the condition, completing as soon as the predicate returns false.
Type Parameters
T
Exceptions
- ArgumentNullException
Thrown if
predicateis null.
TakeWhile<T>(IObservableAsync<T>, Func<T, CancellationToken, ValueTask<bool>>)
Returns elements from the observable sequence as long as the specified asynchronous condition is true, then completes.
public static IObservableAsync<T> TakeWhile<T>(this IObservableAsync<T> @this, Func<T, CancellationToken, ValueTask<bool>> predicate) where T : notnull
Parameters
thisIObservableAsync<T>predicateFunc<T, CancellationToken, ValueTask<bool>>An asynchronous function to test each element for a condition. Receives the element and a cancellation token.
Returns
- IObservableAsync<T>
An observable sequence that contains elements from the source sequence that satisfy the condition, completing as soon as the predicate returns false.
Type Parameters
T
Exceptions
- ArgumentNullException
Thrown if
predicateis null.
Take<T>(IObservableAsync<T>, int)
Returns a new observable sequence that emits only the first specified number of elements from the source sequence.
public static IObservableAsync<T> Take<T>(this IObservableAsync<T> @this, int count) where T : notnull
Parameters
thisIObservableAsync<T>countintThe maximum number of elements to emit from the source sequence. Must be greater than or equal to zero.
Returns
- IObservableAsync<T>
An observable sequence that contains at most the first
countelements from the source sequence. Ifcountis zero, the resulting sequence completes immediately without emitting any elements.
Type Parameters
T
Remarks
If the source sequence contains fewer elements than count, all
available elements are emitted and the sequence completes. This method does not modify the source sequence;
it returns a new sequence with the specified behavior.
Exceptions
- ArgumentOutOfRangeException
Thrown if
countis less than zero.
Throttle<T>(IObservableAsync<T>, TimeSpan, TimeProvider?)
Ignores elements from the source sequence that are followed by another element within the specified time span. Only the last element in each burst is forwarded.
public static IObservableAsync<T> Throttle<T>(this IObservableAsync<T> @this, TimeSpan dueTime, TimeProvider? timeProvider = null)
Parameters
thisIObservableAsync<T>dueTimeTimeSpanThe time span that must elapse after the last element before it is forwarded. Must be non-negative.
timeProviderTimeProviderAn optional time provider for controlling timing. If null, System is used.
Returns
- IObservableAsync<T>
An observable sequence containing only those elements that are not followed by another element within the specified due time.
Type Parameters
T
Exceptions
- ArgumentOutOfRangeException
Thrown if
dueTimeis negative.
Throw<T>(Exception)
Creates an observable sequence that terminates immediately with the specified exception.
public static IObservableAsync<T> Throw<T>(Exception error)
Parameters
errorExceptionThe exception to be propagated to observers as an error notification. Cannot be null.
Returns
- IObservableAsync<T>
An observable sequence of type
Tthat signals the specified exception upon subscription.
Type Parameters
TThe type of the elements in the observable sequence.
Remarks
Use this method to create an observable sequence that fails immediately, which can be useful for testing error handling or representing error conditions in reactive workflows.
Exceptions
- ArgumentNullException
Thrown if
erroris null.
Timeout<T>(IObservableAsync<T>, TimeSpan, IObservableAsync<T>, TimeProvider?)
Applies a timeout policy to the observable sequence. If the next element is not received within the specified time span, the sequence switches to the specified fallback observable.
public static IObservableAsync<T> Timeout<T>(this IObservableAsync<T> @this, TimeSpan timeout, IObservableAsync<T> fallback, TimeProvider? timeProvider = null)
Parameters
thisIObservableAsync<T>timeoutTimeSpanThe maximum time span allowed between consecutive elements. Must be positive.
fallbackIObservableAsync<T>The fallback observable to switch to when a timeout occurs. Cannot be null.
timeProviderTimeProviderAn optional time provider for controlling timing. If null, System is used.
Returns
- IObservableAsync<T>
An observable sequence that mirrors the source, switching to the fallback sequence if any inter-element interval exceeds the specified timeout.
Type Parameters
T
Exceptions
- ArgumentOutOfRangeException
Thrown if
timeoutis negative or zero.- ArgumentNullException
Thrown if
fallbackis null.
Timeout<T>(IObservableAsync<T>, TimeSpan, TimeProvider?)
Applies a timeout policy to the observable sequence. If the next element is not received within the specified time span, the sequence completes with a TimeoutException.
public static IObservableAsync<T> Timeout<T>(this IObservableAsync<T> @this, TimeSpan timeout, TimeProvider? timeProvider = null)
Parameters
thisIObservableAsync<T>timeoutTimeSpanThe maximum time span allowed between consecutive elements. Must be positive.
timeProviderTimeProviderAn optional time provider for controlling timing. If null, System is used.
Returns
- IObservableAsync<T>
An observable sequence that mirrors the source but completes with a TimeoutException if any inter-element interval exceeds the specified timeout.
Type Parameters
T
Exceptions
- ArgumentOutOfRangeException
Thrown if
timeoutis negative or zero.
Timer(TimeSpan, TimeProvider?)
Creates an observable sequence that produces a single value (0) after the specified delay, then completes.
public static IObservableAsync<long> Timer(TimeSpan dueTime, TimeProvider? timeProvider = null)
Parameters
dueTimeTimeSpanThe time span after which to produce the value. Must be non-negative.
timeProviderTimeProviderAn optional time provider for controlling timing. If null, System is used.
Returns
- IObservableAsync<long>
An observable sequence that produces a single value after the specified delay and then completes.
Exceptions
- ArgumentOutOfRangeException
Thrown if
dueTimeis negative.
Timer(TimeSpan, TimeSpan, TimeProvider?)
Creates an observable sequence that produces a single value (0) after the specified delay, then continues to produce sequential values at each specified period.
public static IObservableAsync<long> Timer(TimeSpan dueTime, TimeSpan period, TimeProvider? timeProvider = null)
Parameters
dueTimeTimeSpanThe initial delay before the first value is produced. Must be non-negative.
periodTimeSpanThe interval between subsequent values after the initial delay. Must be positive.
timeProviderTimeProviderAn optional time provider for controlling timing. If null, System is used.
Returns
- IObservableAsync<long>
An observable sequence that produces values starting after the initial delay and continuing at the specified period.
Exceptions
- ArgumentOutOfRangeException
Thrown if
dueTimeis negative orperiodis non-positive.
ToAsyncEnumerable<T>(IObservableAsync<T>, Func<Channel<T>>, Func<Exception, CancellationToken, ValueTask>?)
Converts the specified observable sequence to an asynchronous enumerable sequence, enabling consumption using asynchronous iteration.
public static IAsyncEnumerable<T> ToAsyncEnumerable<T>(this IObservableAsync<T> @this, Func<Channel<T>> channelFactory, Func<Exception, CancellationToken, ValueTask>? onErrorResume = null)
Parameters
thisIObservableAsync<T>The observable sequence to convert to an asynchronous enumerable.
channelFactoryFunc<Channel<T>>A factory function that creates a new channel used to buffer items between the observable and the asynchronous enumerable. The channel controls the buffering and backpressure behavior.
onErrorResumeFunc<Exception, CancellationToken, ValueTask>An optional asynchronous callback invoked when an error occurs in the observable sequence. If provided, this function can handle the exception and determine how the sequence should resume or complete. If null, the sequence completes with the error.
Returns
- IAsyncEnumerable<T>
An asynchronous enumerable sequence that yields the elements produced by the observable sequence. The enumeration completes when the observable completes or an unhandled error occurs.
Type Parameters
TThe type of elements in the observable and resulting asynchronous enumerable sequence.
Remarks
The returned asynchronous enumerable reflects the items and completion behavior of the source
observable. The buffering and concurrency characteristics depend on the channel created by channelFactory. If onErrorResume is provided, it can be used to suppress or handle
errors from the observable; otherwise, errors are propagated to the enumerator.
Exceptions
- ArgumentNullException
Thrown if
thisorchannelFactoryis null.
ToDictionaryAsync<T, TKey>(IObservableAsync<T>, Func<T, TKey>, IEqualityComparer<TKey>?, CancellationToken)
Asynchronously creates a dictionary from the elements of the sequence, using the specified key selector function.
public static ValueTask<Dictionary<TKey, T>> ToDictionaryAsync<T, TKey>(this IObservableAsync<T> @this, Func<T, TKey> keySelector, IEqualityComparer<TKey>? comparer = null, CancellationToken cancellationToken = default) where T : notnull where TKey : notnull
Parameters
thisIObservableAsync<T>keySelectorFunc<T, TKey>A function to extract a key from each element in the sequence. Cannot be null.
comparerIEqualityComparer<TKey>An optional equality comparer to compare keys. If null, the default equality comparer for the key type is used.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<Dictionary<TKey, T>>
A task that represents the asynchronous operation. The task result contains a dictionary mapping keys to elements from the sequence.
Type Parameters
TTKeyThe type of the keys in the resulting dictionary. Must be non-nullable.
Exceptions
- ArgumentNullException
Thrown if the keySelector parameter is null.
ToDictionaryAsync<T, TKey, TValue>(IObservableAsync<T>, Func<T, TKey>, Func<T, TValue>, IEqualityComparer<TKey>?, CancellationToken)
Asynchronously creates a dictionary from the elements of the sequence using the specified key and element selector functions.
public static ValueTask<Dictionary<TKey, TValue>> ToDictionaryAsync<T, TKey, TValue>(this IObservableAsync<T> @this, Func<T, TKey> keySelector, Func<T, TValue> elementSelector, IEqualityComparer<TKey>? comparer = null, CancellationToken cancellationToken = default) where T : notnull where TKey : notnull where TValue : notnull
Parameters
thisIObservableAsync<T>keySelectorFunc<T, TKey>A function to extract a key from each element in the sequence.
elementSelectorFunc<T, TValue>A function to map each element in the sequence to a value in the resulting dictionary.
comparerIEqualityComparer<TKey>An optional equality comparer to compare keys. If null, the default equality comparer for the key type is used.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<Dictionary<TKey, TValue>>
A task that represents the asynchronous operation. The task result contains a dictionary mapping keys to values as defined by the selector functions.
Type Parameters
TTKeyThe type of the keys in the resulting dictionary. Must be non-nullable.
TValueThe type of the values in the resulting dictionary.
Remarks
If multiple elements produce the same key, an exception may be thrown. The operation is performed asynchronously and can be cancelled using the provided cancellation token.
Exceptions
- ArgumentNullException
Thrown if
keySelectororelementSelectoris null.
ToListAsync<T>(IObservableAsync<T>, CancellationToken)
Asynchronously collects all elements from the source sequence into a list.
public static ValueTask<List<T>> ToListAsync<T>(this IObservableAsync<T> @this, CancellationToken cancellationToken = default) where T : notnull
Parameters
thisIObservableAsync<T>cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.
Returns
- ValueTask<List<T>>
A task that represents the asynchronous operation. The task result contains a list of all elements in the source sequence, in the order they were received.
Type Parameters
T
ToObservableAsync(Task)
Converts the specified task into an asynchronous observable sequence that signals completion when the task finishes.
public static IObservableAsync<Unit> ToObservableAsync(this Task @this)
Parameters
thisTaskThe task to be observed. Cannot be null.
Returns
- IObservableAsync<Unit>
An asynchronous observable sequence that emits a single value when the task completes successfully, followed by a completion notification.
Remarks
The returned observable emits a single unit value upon task completion and then signals completion. If the task is canceled or fails, the observable will propagate the corresponding error. This method is useful for integrating task-based operations into observable workflows.
ToObservableAsync<T>(IAsyncEnumerable<T>)
Converts an asynchronous enumerable sequence to an asynchronous observable sequence.
public static IObservableAsync<T> ToObservableAsync<T>(this IAsyncEnumerable<T> @this)
Parameters
thisIAsyncEnumerable<T>The asynchronous enumerable sequence to convert. Cannot be null.
Returns
- IObservableAsync<T>
An asynchronous observable sequence that emits the elements of the source sequence.
Type Parameters
TThe type of elements in the source sequence.
Remarks
The returned observable emits each element from the source sequence as it is produced and signals completion when the source sequence ends. Cancellation is supported via the observer's cancellation token.
ToObservableAsync<T>(IEnumerable<T>)
Converts the specified enumerable sequence to an asynchronous observable sequence, emitting each element in the background.
public static IObservableAsync<T> ToObservableAsync<T>(this IEnumerable<T> @this)
Parameters
thisIEnumerable<T>The enumerable sequence to convert to an asynchronous observable. Cannot be null.
Returns
- IObservableAsync<T>
An asynchronous observable sequence that emits each element from the source enumerable and completes when all elements have been emitted.
Type Parameters
TThe type of elements in the source sequence.
Remarks
The returned observable emits items on a background thread. Cancellation is supported via the observer's cancellation token. If the source sequence is empty, the observable completes immediately.
ToObservableAsync<T>(Task<T>)
Converts a task representing a single asynchronous value into an observable sequence that emits the result when the task completes.
public static IObservableAsync<T> ToObservableAsync<T>(this Task<T> @this)
Parameters
thisTask<T>The task to convert to an asynchronous observable sequence. Cannot be null.
Returns
- IObservableAsync<T>
An asynchronous observable sequence that emits the result of the task when it completes, followed by a completion notification.
Type Parameters
TThe type of the value produced by the task and emitted by the observable sequence.
Remarks
The returned observable will emit the task's result and then complete. If the task is canceled or fails, the observable will propagate the corresponding error. The task is awaited in the background, and cancellation is supported via the observable's subscription.
Using<T, TResource>(Func<CancellationToken, ValueTask<TResource>>, Func<TResource, IObservableAsync<T>>)
Creates an observable sequence that manages the lifetime of an asynchronous resource, ensuring the resource is disposed when the sequence terminates.
public static IObservableAsync<T> Using<T, TResource>(Func<CancellationToken, ValueTask<TResource>> resourceFactory, Func<TResource, IObservableAsync<T>> observableFactory) where TResource : IAsyncDisposable
Parameters
resourceFactoryFunc<CancellationToken, ValueTask<TResource>>A function that asynchronously creates the resource to be used by the observable sequence. The function receives a CancellationToken and returns a ValueTask<TResult> representing the asynchronous creation of the resource.
observableFactoryFunc<TResource, IObservableAsync<T>>A function that, given the created resource, returns an ObservableAsync<T> representing the observable sequence that uses the resource.
Returns
- IObservableAsync<T>
An ObservableAsync<T> that uses the specified resource and ensures the resource is disposed asynchronously when the sequence completes or an error occurs.
Type Parameters
TThe type of the elements produced by the observable sequence.
TResourceThe type of the asynchronous resource that implements IAsyncDisposable.
Remarks
The resource is created for each subscription and is disposed asynchronously when the observable sequence terminates, either by completion or error. If the observable factory throws an exception, the resource is disposed before the exception is propagated. This method is useful for managing resources that must be disposed when no longer needed, such as streams or database connections, in conjunction with asynchronous observable sequences.
WaitCompletionAsync<T>(IObservableAsync<T>, CancellationToken)
Asynchronously waits for the observable sequence to complete without retrieving any values.
public static ValueTask WaitCompletionAsync<T>(this IObservableAsync<T> @this, CancellationToken cancellationToken = default)
Parameters
thisIObservableAsync<T>The observable sequence to wait for completion.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the wait operation.
Returns
- ValueTask
A ValueTask that represents the asynchronous wait operation.
Type Parameters
TThe type of the elements in the observable sequence.
Remarks
This method subscribes to the observable sequence and completes when the sequence signals completion or when the operation is canceled. Any values produced by the sequence are ignored.
Where<T>(IObservableAsync<T>, Func<T, bool>)
Creates a new observable sequence that contains only the elements from the current sequence that satisfy the specified predicate.
public static IObservableAsync<T> Where<T>(this IObservableAsync<T> @this, Func<T, bool> predicate) where T : notnull
Parameters
thisIObservableAsync<T>predicateFunc<T, bool>A function to test each element for a condition. The element is included in the resulting sequence if the function returns true.
Returns
- IObservableAsync<T>
An observable sequence that contains elements from the current sequence that satisfy the specified predicate.
Type Parameters
T
Remarks
The resulting observable emits only those elements for which the predicate returns true. The order and timing of element emission are preserved
from the original sequence.
Where<T>(IObservableAsync<T>, Func<T, CancellationToken, ValueTask<bool>>)
Creates a new observable sequence that contains only the elements from the source sequence that satisfy the specified asynchronous predicate.
public static IObservableAsync<T> Where<T>(this IObservableAsync<T> @this, Func<T, CancellationToken, ValueTask<bool>> predicate) where T : notnull
Parameters
thisIObservableAsync<T>predicateFunc<T, CancellationToken, ValueTask<bool>>A function that evaluates each element and its associated cancellation token, returning a ValueTask that resolves to true to include the element in the resulting sequence; otherwise, false.
Returns
- IObservableAsync<T>
An observable sequence that emits only those elements for which the predicate returns true.
Type Parameters
T
Remarks
The predicate is invoked asynchronously for each element as it is observed. If the predicate throws an exception or the ValueTask is faulted, the resulting sequence will propagate the error to its observers. The cancellation token provided to the predicate can be used to observe cancellation requests during predicate evaluation.
Wrap<T>(IObserverAsync<T>)
Wraps the specified asynchronous observer in a decorator that ensures consistent behavior and interface compliance.
public static IObserverAsync<T> Wrap<T>(this IObserverAsync<T> observer)
Parameters
observerIObserverAsync<T>The asynchronous observer to wrap. Cannot be null.
Returns
- IObserverAsync<T>
A wrapped asynchronous observer that delegates calls to the specified observer.
Type Parameters
TThe type of the elements observed by the asynchronous observer.
Exceptions
- ArgumentNullException
Thrown if
observeris null.
Yield<T>(IObservableAsync<T>)
Returns an observable sequence that yields control to the current thread's scheduler before emitting items from the source sequence.
public static IObservableAsync<T> Yield<T>(this IObservableAsync<T> @this)
Parameters
thisIObservableAsync<T>The source observable sequence to yield from.
Returns
- IObservableAsync<T>
An observable sequence that emits the same elements as the source, but yields control to the scheduler before each emission.
Type Parameters
TThe type of the elements in the observable sequence.
Remarks
This method can be used to ensure that the source sequence's emissions are scheduled asynchronously, which may help avoid stack overflows or improve responsiveness in certain scenarios.
Zip<T1, T2>(IObservableAsync<T1>, IObservableAsync<T2>)
Combines two observable sequences element-by-element into pairs.
public static IObservableAsync<(T1 First, T2 Second)> Zip<T1, T2>(this IObservableAsync<T1> first, IObservableAsync<T2> second)
Parameters
firstIObservableAsync<T1>The first observable sequence. Cannot be null.
secondIObservableAsync<T2>The second observable sequence. Cannot be null.
Returns
- IObservableAsync<(T1 First, T2 Second)>
An observable sequence of tuples pairing elements from each source.
Type Parameters
T1The type of elements in the first source sequence.
T2The type of elements in the second source sequence.
Exceptions
- ArgumentNullException
Thrown if any argument is null.
Zip<T1, T2, TResult>(IObservableAsync<T1>, IObservableAsync<T2>, Func<T1, T2, TResult>)
Combines two observable sequences element-by-element using the specified result selector.
public static IObservableAsync<TResult> Zip<T1, T2, TResult>(this IObservableAsync<T1> first, IObservableAsync<T2> second, Func<T1, T2, TResult> resultSelector)
Parameters
firstIObservableAsync<T1>The first observable sequence. Cannot be null.
secondIObservableAsync<T2>The second observable sequence. Cannot be null.
resultSelectorFunc<T1, T2, TResult>A function to apply to each pair of elements. Cannot be null.
Returns
- IObservableAsync<TResult>
An observable sequence whose elements are the result of pair-wise combining the source elements using the result selector.
Type Parameters
T1The type of elements in the first source sequence.
T2The type of elements in the second source sequence.
TResultThe type of elements in the result sequence.
Exceptions
- ArgumentNullException
Thrown if any argument is null.