Skip to content

AsyncObservableExtensions.SubscribeAsync(IAsyncObservable<T>, Func<T, StreamSequenceToken, Task>, Func<Exception, Task>, Func<Task>)

SubscribeAsync(IAsyncObservable<T>, Func<T, StreamSequenceToken, Task>, Func<Exception, Task>, Func<Task>)

staticextension
View source
public static Task<StreamSubscriptionHandle<T>> SubscribeAsync<T>(this IAsyncObservable<T> obs, Func<T, StreamSequenceToken, Task> onNextAsync, Func<Exception, Task> onErrorAsync, Func<Task> onCompletedAsync)
Subscribe a consumer to this observable using delegates. This method is a helper for the IAsyncObservable.SubscribeAsync allowing the subscribing class to inline the handler methods instead of requiring an instance of IAsyncObserver.

Parameters

obsIAsyncObservable<T>
The Observable object.
onNextAsyncFunc<T, StreamSequenceToken, Task>
Delegate that is called for IAsyncObserver.OnNextAsync.
onErrorAsyncFunc<Exception, Task>
Delegate that is called for IAsyncObserver.OnErrorAsync.
onCompletedAsyncFunc<Task>
Delegate that is called for IAsyncObserver.OnCompletedAsync.

Returns

A promise for a StreamSubscriptionHandle that represents the subscription. The consumer may unsubscribe by using this handle. The subscription remains active for as long as it is not explicitly unsubscribed.