0

I have this JavaScript pseudocode:

async function main() {

    for(let i=0; i<array.length; i++)  {

        for(let j=0; j<3; j++) {

            let value = await promise thisFunctionReturnsAPromise();

            If(value) {
                // do_something
            }
        }
    }
}

Now I need to iterate 2 promises at time (to speed up the job) and to test each one of them 3 times; so i can't use a simple for anymore.

I need to replace the external for loop.

I was thinking to use async.eachLimit to solve the problem but i can't use await within eachLimit. How can i put an await within async eachLimit to call more then one "test cicle"?

I need something like async.eachLimit because my job needs to go to the next element that needs to be tested after one of the previous two has been tested for a maximum of 3 times.

Sorry for my bad english.

  • No, don't use `async.js`. It's not suited for promise APIs. – Bergi Jun 03 '17 at 16:47
  • Just use `await Promise.all([promise1, promise2, promise3])` – Bergi Jun 03 '17 at 16:48
  • Thanks! Ok but how could i limit promise.all to 2 at a time? – Codewarlock Jun 03 '17 at 16:50
  • Just pass only two then. If you want the third to be started when the first settles, so that you always have 2 task running concurrently, have a look at [this](https://stackoverflow.com/a/39197252/1048572) – Bergi Jun 03 '17 at 19:50

0 Answers0