Skip to content

Instantly share code, notes, and snippets.

@NuroDev
Last active July 8, 2022 12:08
Show Gist options
  • Save NuroDev/e5db97f3fd05788156e1407e21567fc3 to your computer and use it in GitHub Desktop.
Save NuroDev/e5db97f3fd05788156e1407e21567fc3 to your computer and use it in GitHub Desktop.
πŸ›‘ Async Timeout ─ Asynchronous wrapper for the standard JavaScript setTimeout function
const setTimeoutAsync = <
TCallback extends Function = () => void | Promise<void>
>(
cb: TCallback,
delay: number
) =>
new Promise((resolve) =>
setTimeout(() => {
resolve(cb());
}, delay)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment