Last active
August 29, 2015 14:14
-
-
Save ben-bradley/add5cfceed5018698b38 to your computer and use it in GitHub Desktop.
Promise wait/delay
This file contains hidden or 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
| // 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