Skip to content

How does deno_core get notified when there is a new task in queueMicroktask? #25930

Answered by bartlomieju
linrongbin16 asked this question in Q&A
Discussion options

You must be logged in to vote

I mean, in a js runtime such like node/deno, the event loop will block the main thread and wait for callbacks trigger it, not forever loop and use 100% CPU core.

That's correct - only if there's some scheduled work the event loop is blocking. If there is no scheduled work then nothing can push more microtasks onto the queue.

deno_core implement the queueMicrotask API by itself. i.e. it creates a queue inside rust side, and expose an ops API (for example ops.queue_microtask) to javascript side, then set globalThis.queueMicrotask = function(callback) { ops.queue_microtask(callback); }. So deno_core can get notified when the queue is triggered.

Not really, when microtask is queued it use…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@linrongbin16
Comment options

Answer selected by linrongbin16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants