Skip to content

Instantly share code, notes, and snippets.

@itaditya
Created July 5, 2021 11:18
Show Gist options
  • Save itaditya/583451ed4db6ac4cfec418e4343a5b52 to your computer and use it in GitHub Desktop.
Save itaditya/583451ed4db6ac4cfec418e4343a5b52 to your computer and use it in GitHub Desktop.
Easy way to delay promise resolving
function sleep(duration, shouldFail) {
return new Promise((resolve, reject) => {
const cb = shouldFail ? reject : resolve;
setTimeout(() => cb(), duration);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment