Last active
September 19, 2016 19:11
-
-
Save joepie91/583db45f3a30552a7cd2 to your computer and use it in GitHub Desktop.
Bluebird Promise.delay for ES6 Promises
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
var Promise = require("es6-promise").Promise; | |
module.exports = function(delay){ | |
return function(value) { | |
return new Promise(function(resolve, reject){ | |
setTimeout(function(){ | |
resolve(value); | |
}, 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
var delay = require("./delay"); | |
// ... | |
.then(function(value){ | |
return doAnotherThing(); | |
}) | |
.then(delay(5000)) | |
.then(function(value){ | |
return doThingAfterFiveSeconds(value); | |
}) | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment