-
Notifications
You must be signed in to change notification settings - Fork 1
Cooldown
runtoolkit edited this page Apr 13, 2026
·
1 revision
Per-entity, per-key cooldown tracker. Supports pause, resume, and extend.
import { Cooldown } from './src/cooldown.js';
const cd = new Cooldown();// Set a 3-second cooldown for entity 'alice', key 'ability'
cd.set('alice', 'ability', 3000);
// Check
cd.isReady('alice', 'ability'); // true when expired
cd.remaining('alice', 'ability'); // ms remaining (0 if ready)
cd.check('alice', 'ability'); // 1 if active, 0 if ready
// Clear
cd.clear('alice', 'ability'); // remove one cooldown
cd.clearAll('alice'); // remove all cooldowns for entitycd.extend('alice', 'ability', 1000); // add 1s to remaining time
// returns false if cooldown doesn't exist
cd.pause('alice', 'ability'); // freeze the countdown
// returns false if already paused or not found
cd.resume('alice', 'ability'); // resume — elapsed pause time is added back
// returns false if not paused or not foundremaining() accounts for paused state — it returns the frozen value while paused.
cd.detail('alice');
// → [{ key, remaining, paused }, ...]