Last active
July 6, 2017 20:53
-
-
Save todgru/1e942d04a305cc50276cbfe53b9f334d to your computer and use it in GitHub Desktop.
adding a delay inside a Promise
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
// 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