AsyncObservable.cs 974 B

1234567891011121314151617181920212223242526272829
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT License.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Threading.Tasks;
  5. namespace System.Reactive
  6. {
  7. public class AsyncObservable<T> : AsyncObservableBase<T>
  8. {
  9. private readonly Func<IAsyncObserver<T>, Task<IAsyncDisposable>> _subscribeAsync;
  10. public AsyncObservable(Func<IAsyncObserver<T>, Task<IAsyncDisposable>> subscribeAsync)
  11. {
  12. if (subscribeAsync == null)
  13. throw new ArgumentNullException(nameof(subscribeAsync));
  14. _subscribeAsync = subscribeAsync;
  15. }
  16. protected override Task<IAsyncDisposable> SubscribeAsyncCore(IAsyncObserver<T> observer)
  17. {
  18. if (observer == null)
  19. throw new ArgumentNullException(nameof(observer));
  20. return _subscribeAsync(observer);
  21. }
  22. }
  23. }