javascript - How to observe multiple task queues in JS event loop -
i'm reading an article explains event loop , execution timings. in it, it's mention there can multiple task queues event loop can choose execute tasks. main question when browser decide create new queue? i've tried observe happening, far haven't been able to.
contrasted this other article on subject, there's no mention of multiple queues, i'm either misunderstanding or 1 of 2 articles incorrect somewhere.
i believe 2 articles in question using different terminology.
in article 1:
an event loop has multiple task sources guarantees execution order within source...
in article 2
the event loop can have multiple task queues... tasks must processed in insertion order in every queue.
to answer own question observing different queues, think it's simple this:
function foo() { console.log('start of queue'); bar(); promise.resolve().then(function() { console.log('promise resolved'); }); console.log('end of queue'); } function bar() { settimeout(function() { console.log('start of next queue'); console.log('end of next queue'); }, 0); } foo(); //-> start of queue //-> end of queue //-> promise resolved //-> start of next queue //-> end of next queue the first task queue (or task source) foo(). foo() calls bar(), , bar() calls settimeout() sets new task queue (or task source). way can observe each task queue resolve promise. promise callback inserted micro queue. micro queue tasks executed @ end of every task queue (or task source). because see promise resolved between end of queue , start of next queue console logs, can conclude that we're observing different event queues.
Comments
Post a Comment