I have a function that is using promises and the Q library, essentially I want to wait until all the promises have compelted before returning, but my code is just falling through:
function makeSomething(){
var something = new Something()
Q.all([
somethingPromise1(something)
, somethingPromise2(something)
]).spread(function(resultsFromP1, resultsFromP2){
something.otherValue = resultsFromP2
}).done()
return something
}
var something = makeSomething()
console.log(something.otherValue)
The code is more complicated, but this is the gist. Calling it is more along the lines of
something = _.find(things, function(){})
if(!something ) something = makeSomething()
then
manyMoreInterestingTasks(something)
I don't want my calling code to have to fork on an if. Essentially I want makeSomething too block until it returns. I am new to Node and Q so I apologize if I am abusing the approach...