Observable.Time.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using System;
  2. using System.Collections.Generic;
  3. using UniRx.Operators;
  4. namespace UniRx
  5. {
  6. // Timer, Interval, etc...
  7. public static partial class Observable
  8. {
  9. public static IObservable<long> Interval(TimeSpan period)
  10. {
  11. return new TimerObservable(period, period, Scheduler.DefaultSchedulers.TimeBasedOperations);
  12. }
  13. public static IObservable<long> Interval(TimeSpan period, IScheduler scheduler)
  14. {
  15. return new TimerObservable(period, period, scheduler);
  16. }
  17. public static IObservable<long> Timer(TimeSpan dueTime)
  18. {
  19. return new TimerObservable(dueTime, null, Scheduler.DefaultSchedulers.TimeBasedOperations);
  20. }
  21. public static IObservable<long> Timer(DateTimeOffset dueTime)
  22. {
  23. return new TimerObservable(dueTime, null, Scheduler.DefaultSchedulers.TimeBasedOperations);
  24. }
  25. public static IObservable<long> Timer(TimeSpan dueTime, TimeSpan period)
  26. {
  27. return new TimerObservable(dueTime, period, Scheduler.DefaultSchedulers.TimeBasedOperations);
  28. }
  29. public static IObservable<long> Timer(DateTimeOffset dueTime, TimeSpan period)
  30. {
  31. return new TimerObservable(dueTime, period, Scheduler.DefaultSchedulers.TimeBasedOperations);
  32. }
  33. public static IObservable<long> Timer(TimeSpan dueTime, IScheduler scheduler)
  34. {
  35. return new TimerObservable(dueTime, null, scheduler);
  36. }
  37. public static IObservable<long> Timer(DateTimeOffset dueTime, IScheduler scheduler)
  38. {
  39. return new TimerObservable(dueTime, null, scheduler);
  40. }
  41. public static IObservable<long> Timer(TimeSpan dueTime, TimeSpan period, IScheduler scheduler)
  42. {
  43. return new TimerObservable(dueTime, period, scheduler);
  44. }
  45. public static IObservable<long> Timer(DateTimeOffset dueTime, TimeSpan period, IScheduler scheduler)
  46. {
  47. return new TimerObservable(dueTime, period, scheduler);
  48. }
  49. public static IObservable<Timestamped<TSource>> Timestamp<TSource>(this IObservable<TSource> source)
  50. {
  51. return Timestamp<TSource>(source, Scheduler.DefaultSchedulers.TimeBasedOperations);
  52. }
  53. public static IObservable<Timestamped<TSource>> Timestamp<TSource>(this IObservable<TSource> source, IScheduler scheduler)
  54. {
  55. return new TimestampObservable<TSource>(source, scheduler);
  56. }
  57. public static IObservable<UniRx.TimeInterval<TSource>> TimeInterval<TSource>(this IObservable<TSource> source)
  58. {
  59. return TimeInterval(source, Scheduler.DefaultSchedulers.TimeBasedOperations);
  60. }
  61. public static IObservable<UniRx.TimeInterval<TSource>> TimeInterval<TSource>(this IObservable<TSource> source, IScheduler scheduler)
  62. {
  63. return new UniRx.Operators.TimeIntervalObservable<TSource>(source, scheduler);
  64. }
  65. public static IObservable<T> Delay<T>(this IObservable<T> source, TimeSpan dueTime)
  66. {
  67. return source.Delay(dueTime, Scheduler.DefaultSchedulers.TimeBasedOperations);
  68. }
  69. public static IObservable<TSource> Delay<TSource>(this IObservable<TSource> source, TimeSpan dueTime, IScheduler scheduler)
  70. {
  71. return new DelayObservable<TSource>(source, dueTime, scheduler);
  72. }
  73. public static IObservable<T> Sample<T>(this IObservable<T> source, TimeSpan interval)
  74. {
  75. return source.Sample(interval, Scheduler.DefaultSchedulers.TimeBasedOperations);
  76. }
  77. public static IObservable<T> Sample<T>(this IObservable<T> source, TimeSpan interval, IScheduler scheduler)
  78. {
  79. return new SampleObservable<T>(source, interval, scheduler);
  80. }
  81. public static IObservable<TSource> Throttle<TSource>(this IObservable<TSource> source, TimeSpan dueTime)
  82. {
  83. return source.Throttle(dueTime, Scheduler.DefaultSchedulers.TimeBasedOperations);
  84. }
  85. public static IObservable<TSource> Throttle<TSource>(this IObservable<TSource> source, TimeSpan dueTime, IScheduler scheduler)
  86. {
  87. return new ThrottleObservable<TSource>(source, dueTime, scheduler);
  88. }
  89. public static IObservable<TSource> ThrottleFirst<TSource>(this IObservable<TSource> source, TimeSpan dueTime)
  90. {
  91. return source.ThrottleFirst(dueTime, Scheduler.DefaultSchedulers.TimeBasedOperations);
  92. }
  93. public static IObservable<TSource> ThrottleFirst<TSource>(this IObservable<TSource> source, TimeSpan dueTime, IScheduler scheduler)
  94. {
  95. return new ThrottleFirstObservable<TSource>(source, dueTime, scheduler);
  96. }
  97. public static IObservable<T> Timeout<T>(this IObservable<T> source, TimeSpan dueTime)
  98. {
  99. return source.Timeout(dueTime, Scheduler.DefaultSchedulers.TimeBasedOperations);
  100. }
  101. public static IObservable<T> Timeout<T>(this IObservable<T> source, TimeSpan dueTime, IScheduler scheduler)
  102. {
  103. return new TimeoutObservable<T>(source, dueTime, scheduler);
  104. }
  105. public static IObservable<T> Timeout<T>(this IObservable<T> source, DateTimeOffset dueTime)
  106. {
  107. return source.Timeout(dueTime, Scheduler.DefaultSchedulers.TimeBasedOperations);
  108. }
  109. public static IObservable<T> Timeout<T>(this IObservable<T> source, DateTimeOffset dueTime, IScheduler scheduler)
  110. {
  111. return new TimeoutObservable<T>(source, dueTime, scheduler);
  112. }
  113. }
  114. }