Asynchronous code

This part of the JavaScript course is about code that waits: a program has one call stack, and callbacks wait in a queue that the event loop drains; the first lesson prints four logs in the order that proves it. Timers come next, then promises with then and catch, and the four combinators Promise.all, allSettled, race and any. async and await make the same code read in order, an error climbs a rejection, for await walks an async generator, and an AbortSignal stops work that is no longer wanted. A queue with limited concurrency and the event emitters of node:events close the part.

079 The event loop: the stack, tasks and microtasks the call stack, the task queue of timers, the microtask queue drained first, the order of four logs, and a long loop that holds every callback Open 080 Timers: setTimeout, setInterval and their order setTimeout and its handle, two timers with one delay in registration order, setInterval that clears itself, and clearTimeout before and after the callback Open 081 Promises: then, catch, finally and chaining the executor called at once, the three states, a rejected promise that skips a then, a chain with a failure in the middle, and finally that passes the value on Open 082 Promise.all, allSettled, race and any one delay helper, all for everything in the order of the calls, allSettled for a report without a failure, race and any over the same delays Open 083 async and await an async function returns a promise, await pauses only that function, a try and catch around an await, and a loop against Promise.all in the order of the starts Open 084 Errors in asynchronous code a rejection that climbs through await, an unhandled rejection and its exit code, one top-level try with process.exitCode, and allSettled as a report per call Open 085 for await...of and async generators for await over an async generator, await before a yield, the iterator read by hand with next, and a break that closes the generator Open 086 AbortController and timeouts the controller and its one-time event, a timer cleared on abort, a loop that checks the signal between steps, and AbortSignal.timeout with its TimeoutError Open 087 A queue with limited concurrency everything at once as the problem, a worker loop over a shared index, results written at the index of the item, and the failure that stops the pool but not the running job Open 088 Event emitters: on, once and emit node:events, two listeners of one event, once that removes itself, off and removeAllListeners, and the error event that throws without a listener Open

Lessons