You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think this might just be a matter of me being new to javascript and having so many callbacks etc., however I thought I would see if you can see what I am missing.
I am trying to have a flow similar to this:
async.parallel([
function(callback){
FetchData1(callback);
},
function(callback){
async.waterfall([
function(callback2){
FetchData2(callback2)
},
function(arg1, arg2, callback2){
FetchData3(arg1, arg2,callback2);
}
],function(err, results){
callback(null, results);
});
}],function(err, results){
// run export methods after all fetch calls are done
});
Each of the "FetchData" calls query some webservice and parse the data from it using xml2js. The issue is definitely that there are things happening asynchronously within these calls, but I cannot seem to get it to work correctly no matter what I do.
Is there a way to force waterfall to wait until everything is completely done?
I'm pretty sure the issue is in the second fetch that looks something like:
function FetchData2(arg1, arg2, callback2) {
db.collection('collec', function (err, collection) {
var stream = collection.find({"Week": weekNumber}).streamRecords();
stream.on('data', function(doc){
var parser = new xml2js.Parser({trim: false,normalize: false,emptyTag: '', explicitRoot:true});
parser.addListener('end', function(result) {
for(var i = 0; i < max; i++){ // save to db }
});
//
// get data and then call parser.parseString here
//
});
stream.on('end',function(){
callback2(null,'done');
});
});
}
The text was updated successfully, but these errors were encountered:
Hi,
I think this might just be a matter of me being new to javascript and having so many callbacks etc., however I thought I would see if you can see what I am missing.
I am trying to have a flow similar to this:
async.parallel([
});
Each of the "FetchData" calls query some webservice and parse the data from it using xml2js. The issue is definitely that there are things happening asynchronously within these calls, but I cannot seem to get it to work correctly no matter what I do.
Is there a way to force waterfall to wait until everything is completely done?
I'm pretty sure the issue is in the second fetch that looks something like:
function FetchData2(arg1, arg2, callback2) {
}
The text was updated successfully, but these errors were encountered: