Created
April 13, 2017 16:43
-
-
Save daronwolff/454449ec1756b44c8e363b60f3a63b93 to your computer and use it in GitHub Desktop.
This function is similar to Promise.all but this receives an object. The param names from promisesObject is used to clasify the information
This file contains hidden or 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 resolveObject(promisesObject) { | |
const data = {}; | |
let ready = Promise.resolve(null); | |
Object.keys(promisesObject).forEach((name) => { | |
const promise = promisesObject[name]; | |
ready = ready.then(() => promise) | |
.then((value) => { | |
data[name] = value; | |
}); | |
}); | |
return ready.then(() => data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment