AsyncObserver.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Threading.Tasks;
  5. namespace System.Reactive.Linq
  6. {
  7. public static class AsyncObserver
  8. {
  9. public static IAsyncObserver<T> Create<T>(Func<T, Task> onNextAsync, Func<Exception, Task> onErrorAsync, Func<Task> onCompletedAsync)
  10. {
  11. if (onNextAsync == null)
  12. throw new ArgumentNullException(nameof(onNextAsync));
  13. if (onErrorAsync == null)
  14. throw new ArgumentNullException(nameof(onErrorAsync));
  15. if (onCompletedAsync == null)
  16. throw new ArgumentNullException(nameof(onCompletedAsync));
  17. return new AnonymousAsyncObserver<T>(onNextAsync, onErrorAsync, onCompletedAsync);
  18. }
  19. private sealed class AnonymousAsyncObserver<T> : IAsyncObserver<T>
  20. {
  21. private readonly Func<T, Task> _onNextAsync;
  22. private readonly Func<Exception, Task> _onErrorAsync;
  23. private readonly Func<Task> _onCompletedAsync;
  24. public AnonymousAsyncObserver(Func<T, Task> onNextAsync, Func<Exception, Task> onErrorAsync, Func<Task> onCompletedAsync)
  25. {
  26. _onNextAsync = onNextAsync;
  27. _onErrorAsync = onErrorAsync;
  28. _onCompletedAsync = onCompletedAsync;
  29. }
  30. public Task OnCompletedAsync()
  31. {
  32. throw new NotImplementedException();
  33. }
  34. public Task OnErrorAsync(Exception error)
  35. {
  36. throw new NotImplementedException();
  37. }
  38. public Task OnNextAsync(T value)
  39. {
  40. throw new NotImplementedException();
  41. }
  42. }
  43. }
  44. }