Skip to content

Instantly share code, notes, and snippets.

@pyrsmk
Created July 1, 2022 14:06
Show Gist options
  • Save pyrsmk/9f2242e3c7d02f167aacb29f12f3213e to your computer and use it in GitHub Desktop.
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.
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