feat(utils): add cooldown guard against duplicate actions

Refs: #111
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
nocodeandClaude Opus 5 committed 2026-09-13 12:19:10 +02:00
1 parent 2c9221c728
commit ea7026e83c
1 file changed
+18
+18
View File
@@ -0,0 +1,18 @@
/** In-memory guard against duplicate actions within a time window (M13-T08). */
export function createCooldown(windowMs) {
const entries = new Map();
return {
/** Returns true when the key is free, and locks it for `windowMs`. */
acquire(key) {
const now = Date.now();
const expiresAt = entries.get(key);
if (expiresAt && expiresAt > now) return false;
entries.set(key, now + windowMs);
return true;
},
release(key) {
entries.delete(key);
},
};
}