Glossary / Promise jobs
Promise jobs
Promise jobs are ECMAScript-specified units of work used to run Promise reactions and related Promise resolution procedures. When a Promise settles, its .then, .catch, or .finally reactions are scheduled as jobs rather than invoked inline. The host integrates these jobs with its microtask processing mechanism, so Promise callbacks run after the current synchronous execution stack unwinds.
Reaction scheduling and chaining
Promise.resolve().then(() => console.log("reaction"));
console.log("current");
// current, reaction
Each .then creates and returns a new Promise. The reaction’s return value fulfills the next Promise; a thrown exception rejects it; returning another Promise/thenable adopts its eventual state. Thenable assimilation invokes a callable then according to Promise resolution rules and protects against self-resolution. Handlers added to an already-settled Promise still run asynchronously through a job.
ECMAScript defines Promise Jobs; HTML defines microtask checkpoints and host scheduling. Node.js additionally has process.nextTick, which is not a Promise job and has distinct ordering. Avoid assuming exact ordering across unrelated host task sources; rely on Promise guarantees and documented host behavior.
Debugging
When an expected reaction does not run, check whether the Promise actually settled, whether the chain’s returned Promise is observed, whether a callback threw, and whether a rejection was handled. Long chains and ignored returned Promises often hide failures. Async stack tools can aid debugging but do not change job semantics.
Interview questions
- Do Promise handlers run synchronously for resolved Promises? No; they are scheduled as jobs.
- What does a handler return do? It determines the next Promise’s fulfillment value or adopted state.
- What happens if a handler throws? The next Promise is rejected with that error.
- Is Node nextTick the same as a Promise job? No, it is Node-specific with separate scheduling behavior.