I want to implement waterfall with async and await.
i went through this tried some hands on
The main purpose is i do want to want call async function if any one of above async rejects with an error.
var cont = 1;
function signin (){
console.log(cont);
// i am doing some async
return new Promise((a,b)=>{
if((++cont) === 4){
setTimeout(1000*cont,b,'ab');
} else {
setTimeout(1000*cont,a,'ab');
}
})
}
async function main() {
try {
await signin;
await signin;
await signin;
await signin;
await signin;
await signin;
await signin;
return signin();
} catch(er){
return er;
}
}
main()
In the above, nothing works as expected. what my expected output output is
1
2
3
4
After fourth it should break all the way. And rest of the attempts to signin should not be called.
All signin must be executed in series. Like in waterfall.
Any help?