I'm learning about JS promises and have made some progress in my understanding of things, however unsure how to bring it together with return
and using Q.all
So say I have a function: (getParentsForLocation
returns a promise)
function doBusiness() {
return Q.all(
locations.map(function(item, currentIndex) {
return getParentsForLocation(item.id)
.then(function(res) {
return checkParent(res, currentIndex)
}
});
}))
.then(_.uniq(locations))
}
Then following this i.e. after that map has gone through all elements in the locations
array, I want to run something like underscore's uniq
function: _.uniq(someArrayIHave);
- Do i need to place this in a
Q.all([])
? \ - If so, would it run each method in that array sequentially?
- I presume there is something I'd need to do with that
doBusiness()
function, e.g. return some promise, but unsure how that would look?
Any help appreciated.
Many Thanks.