Skip to content

Instantly share code, notes, and snippets.

@xieranmaya
Last active August 29, 2015 14:22
Show Gist options
  • Save xieranmaya/a4fdc69a1c93abfdf95d to your computer and use it in GitHub Desktop.
Save xieranmaya/a4fdc69a1c93abfdf95d to your computer and use it in GitHub Desktop.
Implement a delay in ES6 Promise.
Promise.prototype.delay = function(duration) {
return this.then(function(value) {
return new Promise(function(resolve) {
setTimeout(function() {
resolve(value)
}, duration)
})
}, function(reason) {
return new Promise(function(resolve, reject) {
setTimeout(function() {
reject(reason)
}, duration)
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment