IScheduler.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. namespace System.Reactive.Concurrency
  5. {
  6. /// <summary>
  7. /// Represents an object that schedules units of work.
  8. /// </summary>
  9. public interface IScheduler
  10. {
  11. /// <summary>
  12. /// Gets the scheduler's notion of current time.
  13. /// </summary>
  14. DateTimeOffset Now { get; }
  15. /// <summary>
  16. /// Schedules an action to be executed.
  17. /// </summary>
  18. /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
  19. /// <param name="state">State passed to the action to be executed.</param>
  20. /// <param name="action">Action to be executed.</param>
  21. /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
  22. IDisposable Schedule<TState>(TState state, Func<IScheduler, TState, IDisposable> action);
  23. /// <summary>
  24. /// Schedules an action to be executed after dueTime.
  25. /// </summary>
  26. /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
  27. /// <param name="state">State passed to the action to be executed.</param>
  28. /// <param name="action">Action to be executed.</param>
  29. /// <param name="dueTime">Relative time after which to execute the action.</param>
  30. /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
  31. IDisposable Schedule<TState>(TState state, TimeSpan dueTime, Func<IScheduler, TState, IDisposable> action);
  32. /// <summary>
  33. /// Schedules an action to be executed at dueTime.
  34. /// </summary>
  35. /// <typeparam name="TState">The type of the state passed to the scheduled action.</typeparam>
  36. /// <param name="state">State passed to the action to be executed.</param>
  37. /// <param name="action">Action to be executed.</param>
  38. /// <param name="dueTime">Absolute time at which to execute the action.</param>
  39. /// <returns>The disposable object used to cancel the scheduled action (best effort).</returns>
  40. IDisposable Schedule<TState>(TState state, DateTimeOffset dueTime, Func<IScheduler, TState, IDisposable> action);
  41. }
  42. }