Scheduler.Async.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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. #if HAS_AWAIT
  5. using System.Reactive.Disposables;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. namespace System.Reactive.Concurrency
  9. {
  10. public static partial class Scheduler
  11. {
  12. /// <summary>
  13. /// Yields execution of the current work item on the scheduler to another work item on the scheduler.
  14. /// The caller should await the result of calling Yield to schedule the remainder of the current work item (known as the continuation).
  15. /// </summary>
  16. /// <param name="scheduler">Scheduler to yield work on.</param>
  17. /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
  18. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
  19. public static SchedulerOperation Yield(this IScheduler scheduler)
  20. {
  21. if (scheduler == null)
  22. throw new ArgumentNullException(nameof(scheduler));
  23. return new SchedulerOperation(a => scheduler.Schedule(a), scheduler.GetCancellationToken());
  24. }
  25. /// <summary>
  26. /// Yields execution of the current work item on the scheduler to another work item on the scheduler.
  27. /// The caller should await the result of calling Yield to schedule the remainder of the current work item (known as the continuation).
  28. /// </summary>
  29. /// <param name="scheduler">Scheduler to yield work on.</param>
  30. /// <param name="cancellationToken">Cancellation token to cancel the continuation to run.</param>
  31. /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
  32. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
  33. public static SchedulerOperation Yield(this IScheduler scheduler, CancellationToken cancellationToken)
  34. {
  35. if (scheduler == null)
  36. throw new ArgumentNullException(nameof(scheduler));
  37. return new SchedulerOperation(a => scheduler.Schedule(a), cancellationToken);
  38. }
  39. /// <summary>
  40. /// Suspends execution of the current work item on the scheduler for the specified duration.
  41. /// The caller should await the result of calling Sleep to schedule the remainder of the current work item (known as the continuation) after the specified duration.
  42. /// </summary>
  43. /// <param name="scheduler">Scheduler to yield work on.</param>
  44. /// <param name="dueTime">Time when the continuation should run.</param>
  45. /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
  46. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
  47. public static SchedulerOperation Sleep(this IScheduler scheduler, TimeSpan dueTime)
  48. {
  49. if (scheduler == null)
  50. throw new ArgumentNullException(nameof(scheduler));
  51. return new SchedulerOperation(a => scheduler.Schedule(dueTime, a), scheduler.GetCancellationToken());
  52. }
  53. /// <summary>
  54. /// Suspends execution of the current work item on the scheduler for the specified duration.
  55. /// The caller should await the result of calling Sleep to schedule the remainder of the current work item (known as the continuation) after the specified duration.
  56. /// </summary>
  57. /// <param name="scheduler">Scheduler to yield work on.</param>
  58. /// <param name="dueTime">Time when the continuation should run.</param>
  59. /// <param name="cancellationToken">Cancellation token to cancel the continuation to run.</param>
  60. /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
  61. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
  62. public static SchedulerOperation Sleep(this IScheduler scheduler, TimeSpan dueTime, CancellationToken cancellationToken)
  63. {
  64. if (scheduler == null)
  65. throw new ArgumentNullException(nameof(scheduler));
  66. return new SchedulerOperation(a => scheduler.Schedule(dueTime, a), cancellationToken);
  67. }
  68. /// <summary>
  69. /// Suspends execution of the current work item on the scheduler until the specified due time.
  70. /// The caller should await the result of calling Sleep to schedule the remainder of the current work item (known as the continuation) at the specified due time.
  71. /// </summary>
  72. /// <param name="scheduler">Scheduler to yield work on.</param>
  73. /// <param name="dueTime">Time when the continuation should run.</param>
  74. /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
  75. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
  76. public static SchedulerOperation Sleep(this IScheduler scheduler, DateTimeOffset dueTime)
  77. {
  78. if (scheduler == null)
  79. throw new ArgumentNullException(nameof(scheduler));
  80. return new SchedulerOperation(a => scheduler.Schedule(dueTime, a), scheduler.GetCancellationToken());
  81. }
  82. /// <summary>
  83. /// Suspends execution of the current work item on the scheduler until the specified due time.
  84. /// The caller should await the result of calling Sleep to schedule the remainder of the current work item (known as the continuation) at the specified due time.
  85. /// </summary>
  86. /// <param name="scheduler">Scheduler to yield work on.</param>
  87. /// <param name="dueTime">Time when the continuation should run.</param>
  88. /// <param name="cancellationToken">Cancellation token to cancel the continuation to run.</param>
  89. /// <returns>Scheduler operation object to await in order to schedule the continuation.</returns>
  90. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> is null.</exception>
  91. public static SchedulerOperation Sleep(this IScheduler scheduler, DateTimeOffset dueTime, CancellationToken cancellationToken)
  92. {
  93. if (scheduler == null)
  94. throw new ArgumentNullException(nameof(scheduler));
  95. return new SchedulerOperation(a => scheduler.Schedule(dueTime, a), cancellationToken);
  96. }
  97. /// <summary>
  98. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  99. /// </summary>
  100. /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
  101. /// <param name="scheduler">Scheduler to schedule work on.</param>
  102. /// <param name="state">State to pass to the asynchronous method.</param>
  103. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  104. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  105. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  106. public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, Func<IScheduler, TState, CancellationToken, Task> action)
  107. {
  108. if (scheduler == null)
  109. throw new ArgumentNullException(nameof(scheduler));
  110. if (action == null)
  111. throw new ArgumentNullException(nameof(action));
  112. return ScheduleAsync_<TState>(scheduler, state, action);
  113. }
  114. /// <summary>
  115. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  116. /// </summary>
  117. /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
  118. /// <param name="scheduler">Scheduler to schedule work on.</param>
  119. /// <param name="state">State to pass to the asynchronous method.</param>
  120. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  121. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  122. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  123. public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
  124. {
  125. if (scheduler == null)
  126. throw new ArgumentNullException(nameof(scheduler));
  127. if (action == null)
  128. throw new ArgumentNullException(nameof(action));
  129. return ScheduleAsync_<TState>(scheduler, state, action);
  130. }
  131. /// <summary>
  132. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  133. /// </summary>
  134. /// <param name="scheduler">Scheduler to schedule work on.</param>
  135. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  136. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  137. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  138. public static IDisposable ScheduleAsync(this IScheduler scheduler, Func<IScheduler, CancellationToken, Task> action)
  139. {
  140. if (scheduler == null)
  141. throw new ArgumentNullException(nameof(scheduler));
  142. if (action == null)
  143. throw new ArgumentNullException(nameof(action));
  144. return ScheduleAsync_(scheduler, default(object), (self, o, ct) => action(self, ct));
  145. }
  146. /// <summary>
  147. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  148. /// </summary>
  149. /// <param name="scheduler">Scheduler to schedule work on.</param>
  150. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  151. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  152. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  153. public static IDisposable ScheduleAsync(this IScheduler scheduler, Func<IScheduler, CancellationToken, Task<IDisposable>> action)
  154. {
  155. if (scheduler == null)
  156. throw new ArgumentNullException(nameof(scheduler));
  157. if (action == null)
  158. throw new ArgumentNullException(nameof(action));
  159. return ScheduleAsync_(scheduler, default(object), (self, o, ct) => action(self, ct));
  160. }
  161. /// <summary>
  162. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  163. /// </summary>
  164. /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
  165. /// <param name="scheduler">Scheduler to schedule work on.</param>
  166. /// <param name="state">State to pass to the asynchronous method.</param>
  167. /// <param name="dueTime">Relative time after which to execute the action.</param>
  168. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  169. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  170. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  171. public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, TimeSpan dueTime, Func<IScheduler, TState, CancellationToken, Task> action)
  172. {
  173. if (scheduler == null)
  174. throw new ArgumentNullException(nameof(scheduler));
  175. if (action == null)
  176. throw new ArgumentNullException(nameof(action));
  177. return ScheduleAsync_(scheduler, state, dueTime, action);
  178. }
  179. /// <summary>
  180. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  181. /// </summary>
  182. /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
  183. /// <param name="scheduler">Scheduler to schedule work on.</param>
  184. /// <param name="state">State to pass to the asynchronous method.</param>
  185. /// <param name="dueTime">Relative time after which to execute the action.</param>
  186. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  187. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  188. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  189. public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, TimeSpan dueTime, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
  190. {
  191. if (scheduler == null)
  192. throw new ArgumentNullException(nameof(scheduler));
  193. if (action == null)
  194. throw new ArgumentNullException(nameof(action));
  195. return ScheduleAsync_(scheduler, state, dueTime, action);
  196. }
  197. /// <summary>
  198. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  199. /// </summary>
  200. /// <param name="scheduler">Scheduler to schedule work on.</param>
  201. /// <param name="dueTime">Relative time after which to execute the action.</param>
  202. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  203. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  204. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  205. public static IDisposable ScheduleAsync(this IScheduler scheduler, TimeSpan dueTime, Func<IScheduler, CancellationToken, Task> action)
  206. {
  207. if (scheduler == null)
  208. throw new ArgumentNullException(nameof(scheduler));
  209. if (action == null)
  210. throw new ArgumentNullException(nameof(action));
  211. return ScheduleAsync_(scheduler, default(object), dueTime, (self, o, ct) => action(self, ct));
  212. }
  213. /// <summary>
  214. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  215. /// </summary>
  216. /// <param name="scheduler">Scheduler to schedule work on.</param>
  217. /// <param name="dueTime">Relative time after which to execute the action.</param>
  218. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  219. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  220. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  221. public static IDisposable ScheduleAsync(this IScheduler scheduler, TimeSpan dueTime, Func<IScheduler, CancellationToken, Task<IDisposable>> action)
  222. {
  223. if (scheduler == null)
  224. throw new ArgumentNullException(nameof(scheduler));
  225. if (action == null)
  226. throw new ArgumentNullException(nameof(action));
  227. return ScheduleAsync_(scheduler, default(object), dueTime, (self, o, ct) => action(self, ct));
  228. }
  229. /// <summary>
  230. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  231. /// </summary>
  232. /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
  233. /// <param name="scheduler">Scheduler to schedule work on.</param>
  234. /// <param name="state">State to pass to the asynchronous method.</param>
  235. /// <param name="dueTime">Absolute time at which to execute the action.</param>
  236. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  237. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  238. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  239. public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, DateTimeOffset dueTime, Func<IScheduler, TState, CancellationToken, Task> action)
  240. {
  241. if (scheduler == null)
  242. throw new ArgumentNullException(nameof(scheduler));
  243. if (action == null)
  244. throw new ArgumentNullException(nameof(action));
  245. return ScheduleAsync_(scheduler, state, dueTime, action);
  246. }
  247. /// <summary>
  248. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  249. /// </summary>
  250. /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
  251. /// <param name="scheduler">Scheduler to schedule work on.</param>
  252. /// <param name="state">State to pass to the asynchronous method.</param>
  253. /// <param name="dueTime">Absolute time at which to execute the action.</param>
  254. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  255. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  256. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  257. public static IDisposable ScheduleAsync<TState>(this IScheduler scheduler, TState state, DateTimeOffset dueTime, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
  258. {
  259. if (scheduler == null)
  260. throw new ArgumentNullException(nameof(scheduler));
  261. if (action == null)
  262. throw new ArgumentNullException(nameof(action));
  263. return ScheduleAsync_(scheduler, state, dueTime, action);
  264. }
  265. /// <summary>
  266. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  267. /// </summary>
  268. /// <param name="scheduler">Scheduler to schedule work on.</param>
  269. /// <param name="dueTime">Absolute time at which to execute the action.</param>
  270. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  271. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  272. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  273. public static IDisposable ScheduleAsync(this IScheduler scheduler, DateTimeOffset dueTime, Func<IScheduler, CancellationToken, Task> action)
  274. {
  275. if (scheduler == null)
  276. throw new ArgumentNullException(nameof(scheduler));
  277. if (action == null)
  278. throw new ArgumentNullException(nameof(action));
  279. return ScheduleAsync_(scheduler, default(object), dueTime, (self, o, ct) => action(self, ct));
  280. }
  281. /// <summary>
  282. /// Schedules work using an asynchronous method, allowing for cooperative scheduling in an imperative coding style.
  283. /// </summary>
  284. /// <param name="scheduler">Scheduler to schedule work on.</param>
  285. /// <param name="dueTime">Absolute time at which to execute the action.</param>
  286. /// <param name="action">Asynchronous method to run the work, using Yield and Sleep operations for cooperative scheduling and injection of cancellation points.</param>
  287. /// <returns>Disposable object that allows to cancel outstanding work on cooperative cancellation points or through the cancellation token passed to the asynchronous method.</returns>
  288. /// <exception cref="ArgumentNullException"><paramref name="scheduler"/> or <paramref name="action"/> is null.</exception>
  289. public static IDisposable ScheduleAsync(this IScheduler scheduler, DateTimeOffset dueTime, Func<IScheduler, CancellationToken, Task<IDisposable>> action)
  290. {
  291. if (scheduler == null)
  292. throw new ArgumentNullException(nameof(scheduler));
  293. if (action == null)
  294. throw new ArgumentNullException(nameof(action));
  295. return ScheduleAsync_(scheduler, default(object), dueTime, (self, o, ct) => action(self, ct));
  296. }
  297. private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, Func<IScheduler, TState, CancellationToken, Task> action)
  298. {
  299. return scheduler.Schedule(state, (self, s) => InvokeAsync(self, s, action));
  300. }
  301. private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
  302. {
  303. return scheduler.Schedule(state, (self, s) => InvokeAsync(self, s, action));
  304. }
  305. private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, TimeSpan dueTime, Func<IScheduler, TState, CancellationToken, Task> action)
  306. {
  307. return scheduler.Schedule(state, dueTime, (self, s) => InvokeAsync(self, s, action));
  308. }
  309. private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, TimeSpan dueTime, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
  310. {
  311. return scheduler.Schedule(state, dueTime, (self, s) => InvokeAsync(self, s, action));
  312. }
  313. private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, DateTimeOffset dueTime, Func<IScheduler, TState, CancellationToken, Task> action)
  314. {
  315. return scheduler.Schedule(state, dueTime, (self, s) => InvokeAsync(self, s, action));
  316. }
  317. private static IDisposable ScheduleAsync_<TState>(IScheduler scheduler, TState state, DateTimeOffset dueTime, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
  318. {
  319. return scheduler.Schedule(state, dueTime, (self, s) => InvokeAsync(self, s, action));
  320. }
  321. private static IDisposable InvokeAsync<TState>(IScheduler self, TState s, Func<IScheduler, TState, CancellationToken, Task<IDisposable>> action)
  322. {
  323. var c = new CancellationDisposable();
  324. var d = new SingleAssignmentDisposable();
  325. action(new CancelableScheduler(self, c.Token), s, c.Token).ContinueWith(t =>
  326. {
  327. if (t.IsCanceled)
  328. return;
  329. if (t.Exception != null)
  330. t.Exception.Handle(e => e is OperationCanceledException);
  331. d.Disposable = t.Result;
  332. }, TaskContinuationOptions.ExecuteSynchronously);
  333. return StableCompositeDisposable.Create(c, d);
  334. }
  335. private static IDisposable InvokeAsync<TState>(IScheduler self, TState s, Func<IScheduler, TState, CancellationToken, Task> action)
  336. {
  337. return InvokeAsync(self, s, (self_, state, ct) => action(self_, state, ct).ContinueWith(_ => Disposable.Empty));
  338. }
  339. private static CancellationToken GetCancellationToken(this IScheduler scheduler)
  340. {
  341. var cs = scheduler as CancelableScheduler;
  342. return cs != null ? cs.Token : CancellationToken.None;
  343. }
  344. class CancelableScheduler : IScheduler
  345. {
  346. private readonly IScheduler _scheduler;
  347. private readonly CancellationToken _cancellationToken;
  348. public CancelableScheduler(IScheduler scheduler, CancellationToken cancellationToken)
  349. {
  350. _scheduler = scheduler;
  351. _cancellationToken = cancellationToken;
  352. }
  353. public CancellationToken Token
  354. {
  355. get { return _cancellationToken; }
  356. }
  357. public DateTimeOffset Now
  358. {
  359. get { return _scheduler.Now; }
  360. }
  361. public IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action)
  362. {
  363. return _scheduler.Schedule(state, action);
  364. }
  365. public IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action)
  366. {
  367. return _scheduler.Schedule(state, dueTime, action);
  368. }
  369. public IDisposable Schedule<TState>(TState state, DateTimeOffset dueTime, Func<IScheduler, TState, IDisposable> action)
  370. {
  371. return _scheduler.Schedule(state, dueTime, action);
  372. }
  373. }
  374. }
  375. }
  376. #endif