mirror of
https://github.com/randyjc/Rahoot.git
synced 2026-03-13 20:15:35 +01:00
Add concurrently
This commit is contained in:
26
socket/utils/cooldown.js
Normal file
26
socket/utils/cooldown.js
Normal file
@@ -0,0 +1,26 @@
|
||||
let cooldownTimeout
|
||||
let cooldownResolve
|
||||
|
||||
export const abortCooldown = () => {
|
||||
clearInterval(cooldownTimeout)
|
||||
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) => setTimeout(r, sec * 1000))
|
||||
Reference in New Issue
Block a user