Skip to content

Instantly share code, notes, and snippets.

@gkedge
Last active August 21, 2016 20:24
Show Gist options
  • Save gkedge/3639acde1d9f6819ec8318d6afa395fa to your computer and use it in GitHub Desktop.
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
(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