Skip to content

Instantly share code, notes, and snippets.

@matt-hensley
Created September 12, 2016 18:12
Show Gist options
  • Save matt-hensley/d5dcbe4484ec885bf19f50c9e8872171 to your computer and use it in GitHub Desktop.
Save matt-hensley/d5dcbe4484ec885bf19f50c9e8872171 to your computer and use it in GitHub Desktop.
hash of promises
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