2
0

ITimedEvents.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #nullable enable
  2. namespace Terminal.Gui.App;
  3. /// <summary>
  4. /// Manages timers.
  5. /// </summary>
  6. public interface ITimedEvents
  7. {
  8. /// <summary>
  9. /// Adds a timeout to the application.
  10. /// </summary>
  11. /// <remarks>
  12. /// When the specified time passes, the callback will be invoked. If the callback returns <see langword="true"/>, the
  13. /// timeout will be
  14. /// reset, repeating the invocation. If it returns <see langword="false"/>, the timeout will stop and be removed. The
  15. /// returned value is a
  16. /// token that can be used to stop the timeout by calling <see cref="Remove"/>.
  17. /// </remarks>
  18. object Add (TimeSpan time, Func<bool> callback);
  19. /// <inheritdoc cref="Add(System.TimeSpan,System.Func{bool})"/>
  20. object Add (Timeout timeout);
  21. /// <summary>
  22. /// Invoked when a new timeout is added. To be used in the case when
  23. /// <see cref="IApplication.StopAfterFirstIteration"/> is <see langword="true"/>.
  24. /// </summary>
  25. event EventHandler<TimeoutEventArgs>? Added;
  26. /// <summary>
  27. /// Removes a previously scheduled timeout.
  28. /// </summary>
  29. /// <remarks>
  30. /// The token parameter is the value returned by <see cref="Add(TimeSpan, Func{bool})"/> or <see cref="Add(Timeout)"/>.
  31. /// </remarks>
  32. /// <returns>
  33. /// <see langword="true"/> if the timeout is successfully removed; otherwise, <see langword="false"/>.
  34. /// This method also returns <see langword="false"/> if the timeout is not found.
  35. /// </returns>
  36. bool Remove (object token);
  37. /// <summary>
  38. /// Runs all timeouts that are due.
  39. /// </summary>
  40. void RunTimers ();
  41. /// <summary>
  42. /// Returns the next planned execution time (key - UTC ticks)
  43. /// for each timeout that is not actively executing.
  44. /// </summary>
  45. SortedList<long, Timeout> Timeouts { get; }
  46. }