Skip to content

Instantly share code, notes, and snippets.

@cheshirecode
Created July 26, 2022 10:47
Show Gist options
  • Save cheshirecode/b628fc1debdd6af5475a75f00a6448d7 to your computer and use it in GitHub Desktop.
Save cheshirecode/b628fc1debdd6af5475a75f00a6448d7 to your computer and use it in GitHub Desktop.
js timeout that invokes callback after delay
async function timeout(cb = () => {}, ms = 1000) {
await new Promise((resolve, reject) => {
let wait = setTimeout(() => {
cb()
clearTimeout(wait);
}, ms);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment