▲ 67 ▼ ich🖍️iel (feddit.org) submitted 2 years ago by TaionTheTram@feddit.org to c/ich_iel@feddit.org 8 comments fedilink hide all child comments
[–] bleistift2@sopuli.xyz 2 points 2 years ago 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) permalink fedilink source