Created
July 26, 2022 10:47
-
-
Save cheshirecode/b628fc1debdd6af5475a75f00a6448d7 to your computer and use it in GitHub Desktop.
js timeout that invokes callback after delay
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
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