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 | |
} |
Top comments (1)
For example, this is especially useful for applications that wait for callbacks that usually have a tiny waiting time, to avoid losing time implementing routines to block/unblock a button (which requires styling, possible more HTML tags, additional JS code, etc...).