liveBook · Manning

Pending state

As explained in Secrets of the JavaScript Ninja, Third Edition

A pending state is the promise state in which the asynchronous operation has not yet fulfilled or rejected.

A pending promise has neither fulfilled nor rejected. It becomes settled when its state changes to fulfilled or rejected, and that change can happen only once. A promise starts pending; its state cannot be read directly from the promise object. section 8.1.1

The executor controls how a promise leaves the pending state:

  • Calling resolve with a normal value fulfills it; resolving with a thenable makes the promise follow that thenable’s outcome. section 8.1.1
  • Calling reject or throwing from the executor rejects it. section 8.1.1
  • A promise returned by then also starts pending and is resolved according to the callback’s return value or thrown error. section 8.1.2
// Creates a promise that’s permanently pending.
new Promise((resolve) =>
  resolve({
    then: () => {},
  }),
);

This promise resolves to a thenable whose then method does nothing, leaving the promise permanently pending. section 8.1.1

How Secrets of the JavaScript Ninja, Third Edition covers it

How deep it goes
Explains promise state transitions, executor controls, thenable resolution, and pending promises in a chain.
Examples
Uses a thenable with a no-op then method to demonstrate a promise that remains pending.
What you can do after
Understand how promises enter and leave the pending state, including how thenables can keep them pending.
How it connects
Connects pending state to promise fulfillment, rejection, executors, thenables, and promise chaining.

Also explained in

Compare how 4 books explain pending state →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Secrets of the JavaScript Ninja, Third Edition. The section links point to the parts of the book it draws on.