Created
September 12, 2016 18:12
-
-
Save matt-hensley/d5dcbe4484ec885bf19f50c9e8872171 to your computer and use it in GitHub Desktop.
hash of promises
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
export function hash(o: Object): Promise<any> { | |
var keys = Object.keys(o); | |
var promises = keys.map(key => Promise.resolve(o[key])); | |
return Promise.all(promises).then(function (values) { | |
return keys.reduce(function (hash, key, i) { | |
hash[key] = values[i]; | |
return hash; | |
}, {}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment