Install this version
v0.1.1rune add @rune/cooldowns@0.1.1Manifest hash sha256:e9692da3561b78a10ac9e4982c8fa2f617e07196a9f1d473ddaeb7b01d91019a
runebook · rune
Bounded keyed cooldowns for commands, abilities, interactions, and games.
Library Rune. Boilerplate code consumed by other Runes — the host never loads it directly. Install it as a dependency of your own Rune and import from it.
rune add @rune/cooldowns@0.1.1Manifest hash sha256:e9692da3561b78a10ac9e4982c8fa2f617e07196a9f1d473ddaeb7b01d91019a
The author declares these capabilities as a guide. Rune scripts run with server access.
No capabilities declared by the author. Rune scripts run with server access.
Keep one timer per action or player. A successful attempt starts the cooldown and a rejected attempt returns the remaining wait.
rune add @rune/cooldowns
import { createCooldowns } from "@rune/cooldowns";
const abilities = createCooldowns({ maxKeys: 5_000 });
function tryDash(playerId: string) {
return abilities.tryStart(playerId + ":dash", 3_000);
}
| Method | Result |
|---|---|
tryStart(key, milliseconds) | Starts a timer on success. Otherwise returns reason: "cooldown" with retryAfterMs, or "capacity" when the key budget is full. |
remaining(key) | Milliseconds left, rounded up, or zero. |
clear(key) | Releases the cooldown, for example when the guarded action fails. |
sweep() | Removes expired entries. A full instance sweeps before refusing new keys. |
The default budget is 10,000 keys. Durations are nonnegative whole
milliseconds, and keys contain 1–256 characters. Entries are in memory for
the lifetime of an instance. Pass a custom clock that returns milliseconds
for deterministic tests.