'while loop not waiting for await

I know there's a ton of these questions but I haven't been able to find one that fits my case. I'm making api calls in a while loop and just don't want to time out my calls by rapid firing them. The while loop doesn't seem to be waiting for the call to finish.

while(it < array.length){
    await apiFunction(array[it]);
    console.log(it);
    it++
}

and the function

async apiFunction(array){
    try{
        (async () => {
            const result = await api.doStuff(array);
            console.dir(result);
        }
    } catch (e) {
        stuff;
    }
}

I've also tried adding a return(result) but that didn't change anything

My console output is

0
1
result
result

How can I get the while loop to wait until the api call is done? so my console looks like

0
result
1
result


Solution 1:[1]

I had too many layers of asynchronicity going I guess. Just removed the async from inside the apiFunction

async apiFunction(array){
    try{
        const result = await api.doStuff(array);
        console.dir(result);
    } catch (e) {
        stuff;
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Arkyris