/** Prune expired cooldown entries to prevent unbounded memory growth. */ function pruneExpiredCooldowns(cooldownMs: number): void { if (lastReflectionBySession.size <= MAX_COOLDOWN_ENTRIES) { return;
} const now = Date.now(); for (const [key, time] of lastReflectionBySession) { if (now - time >= cooldownMs) {
lastReflectionBySession.delete(key);
}
}
}
/** Check if a reflection is allowed (cooldown not active). */
export function isReflectionAllowed(sessionKey: string, cooldownMs?: number): boolean { const cooldown = cooldownMs ?? DEFAULT_COOLDOWN_MS; const lastTime = lastReflectionBySession.get(sessionKey); if (lastTime == null) { returntrue;
} return Date.now() - lastTime >= cooldown;
}
/** Record that a reflection was run for a session. */
export function recordReflectionTime(sessionKey: string, cooldownMs?: number): void {
lastReflectionBySession.set(sessionKey, Date.now());
pruneExpiredCooldowns(cooldownMs ?? DEFAULT_COOLDOWN_MS);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.