#nullable enable
using System.Collections.ObjectModel;
namespace Terminal.Gui;
///
/// Manages timers and idles
///
public interface ITimedEvents
{
///
/// Adds specified idle handler function to main iteration processing. The handler function will be called
/// once per iteration of the main loop after other events have been handled.
///
///
void AddIdle (Func idleHandler);
///
/// Runs all idle hooks
///
void LockAndRunIdles ();
///
/// Runs all timeouts that are due
///
void LockAndRunTimers ();
///
/// Called from to check if there are any outstanding timers or idle
/// handlers.
///
///
/// Returns the number of milliseconds remaining in the current timer (if any). Will be -1 if
/// there are no active timers.
///
/// if there is a timer or idle handler active.
bool CheckTimersAndIdleHandlers (out int waitTimeout);
/// Adds a timeout to the application.
///
/// When time specified passes, the callback will be invoked. If the callback returns true, the timeout will be
/// reset, repeating the invocation. If it returns false, the timeout will stop and be removed. The returned value is a
/// token that can be used to stop the timeout by calling .
///
object AddTimeout (TimeSpan time, Func callback);
/// Removes a previously scheduled timeout
/// The token parameter is the value returned by AddTimeout.
///
/// Returns
///
/// if the timeout is successfully removed; otherwise,
///
/// .
/// This method also returns
///
/// if the timeout is not found.
///
bool RemoveTimeout (object token);
///
/// Returns all currently registered idles. May not include
/// actively executing idles.
///
ReadOnlyCollection> IdleHandlers { get;}
///
/// Returns the next planned execution time (key - UTC ticks)
/// for each timeout that is not actively executing.
///
SortedList Timeouts { get; }
/// Removes an idle handler added with from processing.
///
///
/// if the idle handler is successfully removed; otherwise,
///
/// .
/// This method also returns
///
/// if the idle handler is not found.
bool RemoveIdle (Func fnTrue);
///
/// Invoked when a new timeout is added. To be used in the case when
/// is .
///
event EventHandler? TimeoutAdded;
}