I have array of ajax calls which executes one by one. in between any ajax call fails it should fails remaining calls like waterfall.
var waterfallData = [{
"name":"nodejs"
},{
"name":"javascript"
},{
"name":"angularjs"
},{
"name":"mongodb"
}];
function wf(data,cb){
if(data.name == "angularjs"){
cb(null,"error");
}else{
cb(data,null);
}
}
var finalData = {
"dataCheck":""
}
waterfallData.forEach(function(checkData) {
wf(checkData,function(result){
console.log(result);
return true;
},function(err){
console.log("error",err);
return false;
})
});
Here it is executing as series calls. but i don't want to use async waterfall.
i want to stop loop if any case fails. can anyone help me on this. thanks in advance
If they're ajax calls, then you should use code with Fetch and Promises. Put the code into an async function, and then do:
You can promisify your
wf
function and iteratewaterfallData
using for-loopNow you can use simple for-loop with
successFlag