Last active
August 21, 2016 20:24
-
-
Save gkedge/3639acde1d9f6819ec8318d6afa395fa to your computer and use it in GitHub Desktop.
I like q.js's spread idea to an ordered argument list instead of an array of results
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
(function (Promise:Function /* Strange, but true... according to Flow */) { | |
"use strict" | |
// This function cannot(!) use the 'this'-binding fat arroq: () ==> {} | |
Promise.spread = function (promises:Array, fulfilled:Function, rejected:?Function):Promise { | |
return Promise.all(promises).spread(fulfilled, rejected) | |
} | |
// This function cannot(!) use the 'this'-binding fat arroq: () ==> {} | |
// eslint-disable-next-line no-extend-native | |
Promise.prototype.spread = function (fulfilled:Function, rejected:?Function):Promise { | |
return this.then((allResults:Array):Promise => { | |
return fulfilled(...allResults) | |
}, rejected) | |
} | |
})(Promise) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment