-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5b-promises.js
More file actions
21 lines (19 loc) · 748 Bytes
/
5b-promises.js
File metadata and controls
21 lines (19 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* # Promises
* - promise.then(() => {})
* - async functions
* NOTE: async/await pauses to let execution of promise occur synchronously,
* but that also clears what's on the microtask queue.
*/
(async function microtaskQueues() {
async function cheese() {
return Promise.resolve().then(() => {
process.stdout.write("MicroTQ #2: in an async function!\n");
})
}
setTimeout(() => process.stdout.write("TQ\n"), 0);
queueMicrotask(() => process.stdout.write("MicroTQ #1\n"));
await cheese(); // await synchronous execution of microtask queue and above
// add breakpoint at 20 to see how execution occurs
Promise.resolve().then(() => process.stdout.write("MicroTQ #3\n"));
})();