1
0

AsyncObservable.cs 934 B

1234567891011121314151617181920212223242526
  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>, ValueTask<IAsyncDisposable>> _subscribeAsync;
  10. public AsyncObservable(Func<IAsyncObserver<T>, ValueTask<IAsyncDisposable>> subscribeAsync)
  11. {
  12. _subscribeAsync = subscribeAsync ?? throw new ArgumentNullException(nameof(subscribeAsync));
  13. }
  14. protected override ValueTask<IAsyncDisposable> SubscribeAsyncCore(IAsyncObserver<T> observer)
  15. {
  16. if (observer == null)
  17. throw new ArgumentNullException(nameof(observer));
  18. return _subscribeAsync(observer);
  19. }
  20. }
  21. }