Skip to content

Instantly share code, notes, and snippets.

@todgru
Last active July 6, 2017 20:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todgru/1e942d04a305cc50276cbfe53b9f334d to your computer and use it in GitHub Desktop.
Save todgru/1e942d04a305cc50276cbfe53b9f334d to your computer and use it in GitHub Desktop.
adding a delay inside a Promise
// Sometimes I have a promise chain that returns out of a promise before
// the the execution is actually completed. Maybe i'm not returning correctly?
// Anyway, might be a common problem for a newb, like me.
// here is a way to add a delay in the promise chain to wait for the previous
// promise to complete. This is NOT best practice, but maybe it can be used as
// a troubleshooting tool.
//
...
.then(() => {...})
.then(() => {
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve();
}, 3000);
});
})
.then(() => {...})
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment