| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- // Licensed to the .NET Foundation under one or more agreements.
- // The .NET Foundation licenses this file to you under the Apache 2.0 License.
- // See the LICENSE file in the project root for more information.
- using System.Reactive;
- using System.Threading.Tasks;
- namespace System
- {
- public static class AsyncObservableExtensions
- {
- public static Task<IAsyncDisposable> SubscribeAsync<T>(this IAsyncObservable<T> source, Func<T, Task> onNextAsync)
- {
- if (source == null)
- throw new ArgumentNullException(nameof(source));
- if (onNextAsync == null)
- throw new ArgumentNullException(nameof(onNextAsync));
- return source.SubscribeAsync(new AsyncObserver<T>(onNextAsync, ex => Task.FromException(ex), () => Task.CompletedTask));
- }
- public static Task<IAsyncDisposable> SubscribeAsync<T>(this IAsyncObservable<T> source, Func<T, Task> onNextAsync, Func<Exception, Task> onErrorAsync)
- {
- if (source == null)
- throw new ArgumentNullException(nameof(source));
- if (onNextAsync == null)
- throw new ArgumentNullException(nameof(onNextAsync));
- if (onErrorAsync == null)
- throw new ArgumentNullException(nameof(onErrorAsync));
- return source.SubscribeAsync(new AsyncObserver<T>(onNextAsync, onErrorAsync, () => Task.CompletedTask));
- }
- public static Task<IAsyncDisposable> SubscribeAsync<T>(this IAsyncObservable<T> source, Func<T, Task> onNextAsync, Func<Task> onCompletedAsync)
- {
- if (source == null)
- throw new ArgumentNullException(nameof(source));
- if (onNextAsync == null)
- throw new ArgumentNullException(nameof(onNextAsync));
- if (onCompletedAsync == null)
- throw new ArgumentNullException(nameof(onCompletedAsync));
- return source.SubscribeAsync(new AsyncObserver<T>(onNextAsync, ex => Task.FromException(ex), onCompletedAsync));
- }
- public static Task<IAsyncDisposable> SubscribeAsync<T>(this IAsyncObservable<T> source, Func<T, Task> onNextAsync, Func<Exception, Task> onErrorAsync, Func<Task> onCompletedAsync)
- {
- if (source == null)
- throw new ArgumentNullException(nameof(source));
- if (onNextAsync == null)
- throw new ArgumentNullException(nameof(onNextAsync));
- if (onErrorAsync == null)
- throw new ArgumentNullException(nameof(onErrorAsync));
- if (onCompletedAsync == null)
- throw new ArgumentNullException(nameof(onCompletedAsync));
- return source.SubscribeAsync(new AsyncObserver<T>(onNextAsync, onErrorAsync, onCompletedAsync));
- }
- }
- }
|