Interval.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  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<long> Interval(TimeSpan period)
  11. {
  12. if (period < TimeSpan.Zero)
  13. throw new ArgumentOutOfRangeException(nameof(period));
  14. return Create<long>(observer => AsyncObserver.Interval(observer, period));
  15. }
  16. public static IAsyncObservable<long> Interval(TimeSpan period, IAsyncScheduler scheduler)
  17. {
  18. if (period < TimeSpan.Zero)
  19. throw new ArgumentOutOfRangeException(nameof(period));
  20. if (scheduler == null)
  21. throw new ArgumentNullException(nameof(scheduler));
  22. return Create<long>(observer => AsyncObserver.Interval(observer, period, scheduler));
  23. }
  24. }
  25. public partial class AsyncObserver
  26. {
  27. public static ValueTask<IAsyncDisposable> Interval(IAsyncObserver<long> observer, TimeSpan period) => Timer(observer, period, period);
  28. public static ValueTask<IAsyncDisposable> Interval(IAsyncObserver<long> observer, TimeSpan period, IAsyncScheduler scheduler) => Timer(observer, period, period, scheduler);
  29. }
  30. }