-
-
Save herzi/cc01205a709dfa8b15b3 to your computer and use it in GitHub Desktop.
fully promisified version
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
/** | |
* Turns: { | |
* keyOne: promiseOne, | |
* keyTwo: promiseTwo | |
* } into { | |
* keyOne: resolutionOne, | |
* keyTwo: resolutionTwo | |
* } | |
* | |
* (To avoid messing around with unclear array indices when calling different | |
* kinds of async ops; e.g. different database queries and some file system call) | |
*/ | |
function params(object) { | |
return Q(object).keys().then(function (keys) { | |
return Q.all(keys.map(function (key) { | |
return object[key]; | |
})).then(function (values) { | |
var result = {}; | |
for (var i = 0; i < keys.length; i += 1) { | |
result[keys[i]] = values[i]; | |
} | |
return result; | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment