How does deno_core
get notified when there is a new task in queueMicroktask
?
#25930
-
Hi, I'm learning the Does The APIs are:
This means we don't actually have a way to block and wait for the next microtask, instead we will have to do a forever loop. Here's a stupid sample code to show what I mean: pub fn tick_event_loop(&mut self) {
if self.isolate.has_pending_background_tasks() {
self.isoalte.perform_microtask_checkpoint();
}
}
pub fn run_event_loop(&mut self) {
loop {
self.tick_event_loop();
}
} 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. How does I have some guesses:
Would you please help me with it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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.
Not really, when microtask is queued it uses the
Correct. There must be some other scheduled work that can queue microtasks and potentially schedule more work for the future. |
Beta Was this translation helpful? Give feedback.
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.
Not really, when microtask is queued it use…