Skip to content

Instantly share code, notes, and snippets.

@ben-bradley
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save ben-bradley/add5cfceed5018698b38 to your computer and use it in GitHub Desktop.

Select an option

Save ben-bradley/add5cfceed5018698b38 to your computer and use it in GitHub Desktop.
Promise wait/delay
// Promise can be q.Promise in Node < 11.13
function wait(ms) {
return function(data) {
return Promise(functoin(resolve, reject) {
setTimeout(resolve, ms, data);
});
}
}
aPromise({ foo: 'bar' })
.then(wait(5000)) // !!! =)
.then(anotherPromise)
.catch(function(err) {
throw new Error(err);
})
.done(function(data) {
console.log(data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment