Class ObservableBridgeExtensions
- Namespace
- ReactiveUI.Extensions.Async
- Assembly
- ReactiveUI.Extensions.dll
Provides bridge extension methods to convert between IObservable<T> (System.Reactive) and IObservableAsync<T> (async observable) sequences.
public static class ObservableBridgeExtensions
- Inheritance
-
ObservableBridgeExtensions
Remarks
These methods enable bi-directional interoperability, allowing synchronous and asynchronous reactive streams to be used together in the same code base. Use ToObservableAsync<T>(IObservable<T>) to wrap a classic observable as an async observable, and ToObservable<T>(IObservableAsync<T>) to expose an async observable as a classic IObservable<T>.
Methods
ToObservableAsync<T>(IObservable<T>)
Converts a classic IObservable<T> sequence into an ObservableAsync<T> that forwards all notifications through asynchronous observer callbacks.
public static IObservableAsync<T> ToObservableAsync<T>(this IObservable<T> source)
Parameters
sourceIObservable<T>The classic observable sequence to bridge. Cannot be null.
Returns
- IObservableAsync<T>
An ObservableAsync<T> that mirrors the source observable sequence.
Type Parameters
TThe type of elements in the observable sequence.
Remarks
The returned async observable subscribes to the source IObservable<T> when an async observer subscribes. Because IObservable<T> notifications are synchronous, each OnNext/OnError/OnCompleted callback is awaited sequentially before the next notification is processed.
Disposing the async subscription also disposes the underlying IDisposable subscription to the source observable.
Exceptions
- ArgumentNullException
Thrown if
sourceis null.
ToObservable<T>(IObservableAsync<T>)
Converts an ObservableAsync<T> sequence into a classic IObservable<T> that can be consumed by System.Reactive operators and subscribers.
public static IObservable<T> ToObservable<T>(this IObservableAsync<T> source)
Parameters
sourceIObservableAsync<T>The async observable sequence to bridge. Cannot be null.
Returns
- IObservable<T>
An IObservable<T> that mirrors the async observable sequence.
Type Parameters
TThe type of elements in the observable sequence.
Remarks
The returned IObservable<T> subscribes to the async observable on each Subscribe(IObserver<T>) call. Async OnNext callbacks are awaited sequentially; the synchronous IObserver<T> is notified on the thread that completes each await.
Disposing the IDisposable subscription returned by Subscribe disposes the underlying IAsyncDisposable async subscription.
Exceptions
- ArgumentNullException
Thrown if
sourceis null.