Skip to content

Cooldown

runtoolkit edited this page Apr 13, 2026 · 1 revision

Cooldown

Per-entity, per-key cooldown tracker. Supports pause, resume, and extend.

Constructor

import { Cooldown } from './src/cooldown.js';

const cd = new Cooldown();

Basic usage

// 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 entity

Extend, pause, resume

cd.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 found

remaining() accounts for paused state — it returns the frozen value while paused.


Introspection

cd.detail('alice');
// → [{ key, remaining, paused }, ...]

Clone this wiki locally