Created
July 1, 2022 14:06
-
-
Save pyrsmk/9f2242e3c7d02f167aacb29f12f3213e to your computer and use it in GitHub Desktop.
A simple function that marks a callback as busy to avoid calling it multiple times before it has finished its task.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const busyCallbacks = new Set() | |
export async function busy(callback : () => any) : Promise<any> { | |
if (busyCallbacks.has(callback)) { | |
return | |
} | |
busyCallbacks.add(callback) | |
const value = await callback() | |
busyCallbacks.delete(callback) | |
return value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment