Any await point yields to the eventloop, much like using setImmediate.
Try the following:
const{log}=consoleconstproc=x=>log('processing',x)constd=asyncq=>{// ⚠️ Attention! Achtung! Attenzione! ⚠️// We are awaiting a synchronous value (`undefined`, not a `Promise`) just to create a yield point inside the loop!while(q.length)awaitproc(q.pop())}log('starting')consttask=d([3,5,7,9,11,13])log('started')awaittasklog('finished')
You will get started printed before most of the processing lines.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Any
await
point yields to the eventloop, much like usingsetImmediate
.Try the following:
You will get
started
printed before most of theprocessing
lines.