I have to loop an array, and compute to every element a very heavy task, within several functions, but I need the whole array finished before return the callback. The problem, is that node is not blocking there, is like treating this block of code like asynchronous, cause before it gets done, the callback is returned. What am I missing?
function one(data, callback){
for(var i=0; i < data.length; i++){
result = two(data[i]);
}
callback(result)
}
function two(data){
//process
return three(data);
}
function three(data){
//heavy task
return data;
}
callback(result) is called immediately and I need it blocked in order to have the array processed. This was already moved to child process, so it is pretended to work that way.