TaionTheTram@feddit.org to ich_iel@feddit.org · 6 months agoich🖍️ielfeddit.orgimagemessage-square8fedilinkarrow-up166arrow-down10
arrow-up166arrow-down1imageich🖍️ielfeddit.orgTaionTheTram@feddit.org to ich_iel@feddit.org · 6 months agomessage-square8fedilink
minus-squarebleistift2@sopuli.xyzlinkfedilinkDeutscharrow-up2·6 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)