Empty.cs 904 B

1234567891011121314151617181920212223242526
  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.Reactive.Concurrency;
  5. namespace System.Reactive.Linq
  6. {
  7. partial class AsyncObservable
  8. {
  9. public static IAsyncObservable<TSource> Empty<TSource>() => Empty<TSource>(ImmediateAsyncScheduler.Instance);
  10. public static IAsyncObservable<TSource> Empty<TSource>(IAsyncScheduler scheduler)
  11. {
  12. if (scheduler == null)
  13. throw new ArgumentNullException(nameof(scheduler));
  14. return Create<TSource>(observer => scheduler.ScheduleAsync(async ct =>
  15. {
  16. ct.ThrowIfCancellationRequested();
  17. await observer.OnCompletedAsync().RendezVous(scheduler);
  18. }));
  19. }
  20. }
  21. }