const anotherAsync = async () => { console.log('Another async called'); for (let i=0; i<=100000; i++) { } console.log('Another async finished'); }; const func = async () => { console.log('async func called'); anotherAsync(); console.log('async func finished'); }; const run = async () => { console.log('calling async func'); await func(); console.log('done'); }; run();El resultado:
calling async func async func called Another async called Another async finished async func finished done Aquí, como puede ver, estoy esperando solo en la función func . no se espera anotherAsync . Entonces, lógicamente, asumiría que la async func finished y done imprimió antes. Another async called como anotherAsync() debería estar en la cola de microtareas hasta que la pila de llamadas aún no esté vacía. Pero aquí no parece ser el caso.
Apreciaré si alguien puede ayudarme a entender por qué se imprime Another async function async func finished la función asíncrona
Mi suposición es que, anotherFunc es parte de func , por lo que await on func activa una espera implícita en anotherFunc o prioriza la ejecución de esas instrucciones para esa función.