All quizzesHard
Advanced Async Patterns — Series 3
Preview — 3 of 10 questions
What is logged?
javascript
const user = new AbortController();
const signal = AbortSignal.any([user.signal, AbortSignal.timeout(1000)]);
const p = new Promise((_, reject) => {
signal.addEventListener('abort', () => reject(signal.reason));
});
p.catch((e) => console.log(e.name));
user.abort();ATimeoutError, after about 1000 ms
BNothing — a composed signal only fires when every input signal aborts.
CAbortError, immediately
DTypeError: AbortSignal.any is not a function
A long computation is split into chunks so the page can render (or the server can serve I/O) between them. Which scheduling primitive actually yields?
AA macrotask — setTimeout(fn, 0), MessageChannel, or scheduler.postTask() — because the event loop only continues once the microtask queue is empty.
BqueueMicrotask(fn), because microtasks have the highest priority and therefore run in their own turn.
CPromise.resolve().then(fn), because a promise callback is asynchronous and so releases the loop.
DNothing yields on its own; only a Web Worker can, because JavaScript is single-threaded.
What is logged, and is there an unhandled rejection?
javascript
const boom = () => Promise.reject(new Error('b'));
Promise.all([Promise.reject(new Error('a')), boom()]).catch((e) => console.log('caught:', e.message));Acaught: b, and no unhandled rejection.
Bcaught: a, plus an unhandled rejection warning for b.
Ccaught: a and caught: b.
Dcaught: a, and no unhandled rejection.
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.