minus-squarebleistift2@sopuli.xyzlinkfedilinkDeutscharrow-up2·4 months agoIch frage mich echt, wie man diesen Cooldown so verkacken kann. const MAX_QUOTA = 6 const COOLDOWN_PERIOD_MS = 30000 let quota = 0 let interval = null function regrow() { if (quota >= MAX_QUOTA) { clearInterval(interval) interval = null return } quota++ } function onClick() { if (quota <= 0) { return } fetch(/**/) .then((res) => { if (!res.ok) { return Promise.reject(res) } quota-- if (!interval) { regrow() } }) } interval = setInterval(regrow, COOLDOWN_PERIOD_MS)
Ich frage mich echt, wie man diesen Cooldown so verkacken kann.
const MAX_QUOTA = 6 const COOLDOWN_PERIOD_MS = 30000 let quota = 0 let interval = null function regrow() { if (quota >= MAX_QUOTA) { clearInterval(interval) interval = null return } quota++ } function onClick() { if (quota <= 0) { return } fetch(/**/) .then((res) => { if (!res.ok) { return Promise.reject(res) } quota-- if (!interval) { regrow() } }) } interval = setInterval(regrow, COOLDOWN_PERIOD_MS)