I have a JavaScript object with unresolved promises within. What would be the most elegant and simple way to resolve all of these promises within the object and continue to next 'then' block only when all of them are resolved?
var Promise = require('bluebird')
var _ = require('lodash')
Promise.all(fetchSomeData)
.then(data => {
/* 'data' contents:
[
{
foo: 'foo1',
bar: 'bar1',
datatofetch: new Promise((resolve,reject) => {...})
},
{
foo: 'foo2',
bar: 'bar2',
datatofetch: new Promise((resolve,reject) => {...})
},
{
foo: 'foo3',
bar: 'bar3',
datatofetch: new Promise((resolve,reject) => {...})
}
...
]
*/
return // TODO: 'data' object with resolved promises
})
.then(dataWithResolvedPromises => {
// do something with dataWithResolvedPromises
})