nodejs waits for an axiosnedb function asyncwait to run the next query

Have you tried making getArt an async function and simply awaiting it?

async function getArt(limit, offset){...}

async function Name(){
  await getArt(10000, 1000); // wait to complete before moving on
  await getArt(10000, 2000); // only execute when above is done
}

Name();

By not assigning the result of await, you simply tell your program to wait for this function to complete prior to moving on to next one.

Side Note:

Why not make a for loop which increments the offset and calls the getArt function?

async function Name(){
  var limit = 10000;
  for(let offset = 0; offset < limit; offset += limit/10){
    await getArt(limit, offset);
  }
}

Name();

I haven’t tested this, but see no reason why it should not work.

Additionally, (to follow good practice guidelines) you should wrap your await statements in a try-catch block to deal with errors like so:

try{
  await getArt(limit, offset);
}
catch(err){
  console.error(err);
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top