Promises in depth · senior
How promises resolve inside: jobs and extra ticks
Settling a promise queues one microtask (a reaction job) per attached handler, but resolving a promise with another promise or thenable costs extra microtask hops (one job to call its then, then the reaction), which is why returning a promise from .then or from an async function delays the chain by two ticks.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Reaction jobs: when a promise settles, each registered handler is queued as a microtask in registration order.
- Resolving with a thenable queues a job that calls thenable.then(resolve, reject); then the inner promise's reaction is another job. That is 2 extra ticks.
- await on a native promise costs 1 tick (V8 7.2+, after the spec started using PromiseResolve). await on a non-promise wraps it, also 1 tick. await on a custom thenable costs more.
- Returning a promise from an async function resolves the function's promise with a promise: 2 extra ticks compared with returning a plain value.
- Thenables: any object with a then method is adopted, even if it isn't a real promise.
- Only output puzzles depend on tick counts. Real code should express order with explicit awaits or chains.
The red pen
Common traps: mistake → fix
Mistake: Returning a promise from then has the same timing as returning a value
Fix: it costs two extra ticks.
Mistake: await always costs three ticks
Fix: that was the old behaviour; native promises now take one.
Easy to hard
Questions interviewers ask, easy to hard
- Why does 'a2' print after 'b3' in this snippet?
- What is a thenable? Show one.
- How many microtask ticks does await take on a native promise? On a thenable?
- Should production code ever depend on tick counts?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.