I'm facing an issue in processing some data - i'll explain by sections hopefully its clear:
So I have the following code:
Q.all(userIDsToProcess.map(function(item) {
return findUserAndAddData(item['option'], item['theID']);
}))
.then(function(){
cleanUpUnsued();
}
And then this method findUserAndAddData
contains 2 for loops kind of like:
var findUserAndAddData = function(oIn, userComingIn) {
var d = Q.defer();
for (var r=0; r<SomeValue; r++) {
for (var x=0; x<SomeValue; x++) {
//Do some processing
}
}
return d.promise;
}
Now the issue I am facing is for each item I send through the Q.all map
to that function I want it to be completely processed before the next one is passed.
I thought return d.promise
would do this however after some debugging I can see it is not.
So the question - how do I send each item
to the findUserAndAddData
method to be processed one by one - from my debugging I can see they are all sent in one go (to maintain async behaviour)?
Hope that makes sense - any help would be appreciated.
Thanks.