Похожие чаты

Can someone help me understand why promises are microtasks? What

led them to not be macrotasks? I can’t find an explanation online

4 ответов

14 просмотров

https://javascript.info/event-loop

POORYAJ- Автор вопроса
Bbundi
https://javascript.info/event-loop

I totally get that. I mean what’s the motivation behind adding promises to the microtask queue rather than the task queue, since the task queue seems quite suitable too

POORYAJ
I totally get that. I mean what’s the motivation b...

Microtasks are usually scheduled for things that should happen straight after the currently executing script, such as reacting to a batch of actions, or to make something async without taking the penalty of a whole new task. The microtask queue is processed after callbacks as long as no other JavaScript is mid-execution, and at the end of each task. Any additional microtasks queued during microtasks are added to the end of the queue and also processed. Once a promise settles, or if it has already settled, it queues a microtask for its reactionary callbacks. This ensures promise callbacks are async even if the promise has already settled. So calling .then(yey, nay) against a settled promise immediately queues a microtask. This is why promise1 and promise2 are logged after script end, as the currently running script must finish before microtasks are handled. promise1 and promise2 are logged before setTimeout, as microtasks always happen before the next task.

POORYAJ
I totally get that. I mean what’s the motivation b...

I guess to make us use promises even when we are not performing any asynchronous task and want it to execute at the immediate future

Похожие вопросы

Обсуждают сегодня

вопрос: кто как решает вопрос с динамической подгрузкой скриптов для отдельных страниц с включенным turbo router?
Sergei Toroptsev
25
Great news for DePIN fans 🫵🏻 Synternet’s $NOIA token is now supported by ioPay, a multichain wallet from IoTeX! 🫡 https://x.com/synternet_com/status/1792589757471408572?s=46
Emilis
16
Сообщение* в закодированном виде. То есть, просто сделать sendMessage?text=Привет бла-бла! не получится, надо в HEX переводить, и добавлять процент, типа такого: sendMessage?t...
КТ315
21
You ever fuck a fat chick from behind and you’re missing out on a solid inch or two of penetration because of her fat ass?
Genghis Jhan
11
@LGCYMan @JustinKKW Q/A List 1. this part confuses me on #8: "From there, a bridge between erc20 LGXY and erc20 LGXY will be out once that swap is closed." does this mean ...
Sig | LGCY | BattleVerse L1 | BitWin
1
А случайно нет ли в паскале штатной возможности передать указатель и количество туда где array of в качестве аргумента?
zamtmn
25
Nice, похоже из-за portage torbrowser словил ошибку The proxy server is refusing connections. Поэтому видимо все рекомендуют с сайта .desktop качать, но а как же тогда компиля...
Ari
10
> комьюнити я бы не судил по этому чату. Как мы видели по статам просмотров нескольких телеговских постов, то в чате их набивается 30-40 или даже выше, когда как общаются акти...
Constantin F.
4
Anyone here suffers from unexplained aural migraines, who would be up for talking for a bit? Doesn't *have* to be aural, but I am not asking about headaches, I mean actual mi...
Martin Rys
58
How do I reach the grant committee for inquiries?
Darlington Gospel
11
Карта сайта