Skip to content

Commit

Permalink
feat(scripting/hooks/useDelay): add uniqueDelay function
Browse files Browse the repository at this point in the history
  • Loading branch information
meszaros-lajos-gyorgy committed Sep 23, 2023
1 parent 09f3540 commit cd9ce17
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/scripting/hooks/useDelay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,25 @@ let delayIdx = 0
export const useDelay = () => {
let delayOffset = 0

return (delayInMs: number = 0) => {
/**
* creates a timer with a unique identifier
*/
const delay = (delayInMs: number = 0) => {
delayOffset += Math.floor(delayInMs)

return `TIMERdelay${++delayIdx} -m 1 ${delayOffset}`
}

/**
* creates a timer without any identification
* so the delay stays unique at runtime
* and consequently being uncancellable with the off parameter
*/
const uniqueDelay = (delayInMs: number = 0) => {
delayOffset += Math.floor(delayInMs)

return `TIMER -m 1 ${delayOffset}`
}

return { delay, uniqueDelay }
}

0 comments on commit cd9ce17

Please sign in to comment.