Monday 25 February 2019

issue with axios, how can i have multiple async await

iam requesting data from website json object,i have some data stored in mongodb, and based on the extracted data i do multiple request to the website json using axios,but the problem is if i request 40 times, the website blocks my request, saying 403, so i want to have timedelay inside the loopfunction timedelay(){return new Promise((resolve,reject)=>{setTimeout(()=>{console.log('time delay')resolve('time delay')},5000)})}function littletimedelay(){return new Promise((resolve,reject)=>{setTimeout(()=>{console.log('time delay')resolve('time delay')},200)})}async function callall(){console.log('called firststep')await firststep()await timedelay()await secondstep()await timedelay()/* await thirdstep()await timedelay()await fourthstep()await timedelay()await fifthstep()*//*secondstep()await dosometimepass()await deletetimepassrecords()await thirdstep()await dosometimepass()await fourthstep()//await fifthstep()//await sixthstep()*/}​then in the second step there is a loop, i want to stop a loop for some 10 seconds, so that the external website dont block me, just delay a little bit for the next request using axiosproblem is when i do it speedily, it blocks​in getdatafrometherscan, i am passing some parameters, in that i want to have some little time delay for next ether addressproblem here is multiple async and await , can it be worked out ?async function firststep(){console.log('firststep')return new Promise((resolve,reject)=>{exchangesethaddresslist.find({}).exec((err,docs)=>{console.log(docs)let ttl=docs.lengthlet i=0let totaleth=0docs.forEach(kk=>{i=i+1console.log(kk.ethaddress)getdataforetherscan(kk.ethaddress,kk.exchange)//here i want to time delayif(i===ttl){resolve('done')}})})})}

Submitted February 25, 2019 at 05:05PM by aminnagpure

No comments:

Post a Comment