0

In this script

    const build_ids = [ {val:1},{val:2} ]

    for (let id in build_ids) {
        console.log(build_ids[id]);
        getStash(build_ids[id], (build) => {
            console.log(build)
        });
    }

    function getStash(build, cb) {
        setTimeout(() => {
            cb(`proccessing ${build.val}`);
        }, 1000);
    }

You will see that the order

{ val: 1 }
{ val: 2 }
proccessing 1
proccessing 2

How can I modify the code so the for loop waits on the async function before going to the next? The outcome in the desired situation would look like this...

{ val: 1 }
proccessing 1
{ val: 2 }
proccessing 2

I maybe asked the question wrong. Please also let me know what i need to be asking.

Omar
  • 2,726
  • 2
  • 32
  • 65

0 Answers0