mirror of
https://github.com/randyjc/Rahoot.git
synced 2026-03-13 20:15:35 +01:00
31 lines
607 B
JavaScript
31 lines
607 B
JavaScript
let cooldownTimeout = null
|
|
let cooldownResolve = null
|
|
|
|
export const abortCooldown = () => {
|
|
clearInterval(cooldownTimeout)
|
|
|
|
if (cooldownResolve) {
|
|
cooldownResolve()
|
|
}
|
|
}
|
|
|
|
export const cooldown = (ms, io, room) => {
|
|
let count = ms - 1
|
|
|
|
return new Promise((resolve) => {
|
|
cooldownResolve = resolve
|
|
|
|
cooldownTimeout = setInterval(() => {
|
|
if (!count) {
|
|
clearInterval(cooldownTimeout)
|
|
resolve()
|
|
}
|
|
|
|
io.to(room).emit("game:cooldown", count)
|
|
count -= 1
|
|
}, 1000)
|
|
})
|
|
}
|
|
|
|
export const sleep = (sec) => new Promise((r) => void setTimeout(r, sec * 1000))
|