Empty.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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.Reactive.Concurrency;
  5. using System.Threading.Tasks;
  6. namespace System.Reactive.Linq
  7. {
  8. public partial class AsyncObservable
  9. {
  10. public static IAsyncObservable<TSource> Empty<TSource>()
  11. {
  12. return Create<TSource>(observer => AsyncObserver.Empty(observer));
  13. }
  14. public static IAsyncObservable<TSource> Empty<TSource>(IAsyncScheduler scheduler)
  15. {
  16. if (scheduler == null)
  17. throw new ArgumentNullException(nameof(scheduler));
  18. return Create<TSource>(observer => AsyncObserver.Empty(observer, scheduler));
  19. }
  20. }
  21. public partial class AsyncObserver
  22. {
  23. public static ValueTask<IAsyncDisposable> Empty<TSource>(IAsyncObserver<TSource> observer) => Empty(observer, ImmediateAsyncScheduler.Instance);
  24. public static ValueTask<IAsyncDisposable> Empty<TSource>(IAsyncObserver<TSource> observer, IAsyncScheduler scheduler)
  25. {
  26. if (observer == null)
  27. throw new ArgumentNullException(nameof(observer));
  28. if (scheduler == null)
  29. throw new ArgumentNullException(nameof(scheduler));
  30. return scheduler.ScheduleAsync(async ct =>
  31. {
  32. if (!ct.IsCancellationRequested)
  33. {
  34. await observer.OnCompletedAsync().RendezVous(scheduler, ct);
  35. }
  36. });
  37. }
  38. }
  39. }