A rate limiter keyed on nothing but time.

The canonical use is a net event handler on the server: a client can trigger a registered net event as fast as it likes, so anything expensive behind one needs a guard.

var cooldown = new Cooldown(1000);
if (!cooldown.tryUse()) return;    // silently drop the spam
doExpensiveThing();

Constructor

new(intervalMs:Int)

Variables

intervalMs:Int

Milliseconds that must elapse between uses.

read onlyready:Bool

Whether a use would be allowed right now, without consuming it.

read onlyremainingMs:Int

Milliseconds until the next use is allowed, or 0 if it is allowed now.

Methods

reset():Void

Makes the next use allowed immediately.

tryUse():Bool

Consumes the cooldown if it is ready, returning whether it was.