Last active
August 29, 2015 14:00
-
-
Save julienw/11362924 to your computer and use it in GitHub Desktop.
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
Promise.prototype.finally = function(callback) { | |
return this.then( | |
function(arg) { | |
function returnArg() { return arg; } | |
return Promise.resolve(arg).then(callback).then(returnArg, returnArg); | |
}, | |
function(arg) { | |
function throwArg() { throw arg; } | |
return Promise.resolve(arg).then(callback).then(throwArg, throwArg); | |
} | |
); | |
}; |
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
Promise.prototype.finally = function(callback) { | |
return this.then( | |
function(arg) { | |
function returnArg() { return arg; } | |
return Promise.resolve().then(callback).then(returnArg, returnArg); | |
}, | |
function(arg) { | |
function throwArg() { throw arg; } | |
return Promise.resolve().then(callback).then(throwArg, throwArg); | |
} | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added a second possibility where we don't pass the arg to the finally callback, as I'm not sure it's useful.