using System; using System.Threading; using System.Threading.Tasks; using Robust.Shared.IoC; using Timer = Robust.Shared.Timing.Timer; namespace Robust.Shared.GameObjects { [Obsolete("Use a system update loop instead")] public static class TimerExtensions { private static TimerComponent EnsureTimerComponent(this EntityUid entity) { var entMan = IoCManager.Resolve(); return entMan.EnsureComponent(entity); } /// /// Schedule an action to be fired after a certain delay. /// The action will be resumed on the main game logic thread. /// /// The entity to add the timer to. /// The length of time, in milliseconds, to wait before firing the action. /// The action to fire. /// [Obsolete("Use a system update loop instead")] public static void SpawnTimer(this EntityUid entity, int milliseconds, Action onFired, CancellationToken cancellationToken = default) { entity .EnsureTimerComponent() .Spawn(milliseconds, onFired, cancellationToken); } /// /// Schedule an action to be fired after a certain delay. /// The action will be resumed on the main game logic thread. /// /// The entity to add the timer to. /// The length of time, to wait before firing the action. /// The action to fire. /// [Obsolete("Use a system update loop instead")] public static void SpawnTimer(this EntityUid entity, TimeSpan duration, Action onFired, CancellationToken cancellationToken = default) { entity .EnsureTimerComponent() .Spawn((int) duration.TotalMilliseconds, onFired, cancellationToken); } /// /// Schedule an action that repeatedly fires after a delay. /// /// The entity to add the timer to. /// The length of time to delay before firing the repeated action. /// The action to fire. /// The CancellationToken for stopping the Timer. [Obsolete("Use a system update loop instead")] public static void SpawnRepeatingTimer(this EntityUid entity, TimeSpan duration, Action onFired, CancellationToken cancellationToken) { entity .EnsureTimerComponent() .SpawnRepeating(duration, onFired, cancellationToken); } } }