liveBook · Manning

Resolved promise

As explained in Secrets of the JavaScript Ninja, Third Edition

A resolved promise is a promise whose resolve or reject function has been called, including one that adopts the state of another promise or thenable.

A resolved promise is one whose resolve or reject function has been called. That does not necessarily mean it is fulfilled or rejected: resolving with another promise or thenable makes it adopt that value’s state, which may still be pending. section 8.1.1

Keep these distinctions in mind:

  • Settled means fulfilled or rejected. A promise resolved with a thenable can remain unsettled. section 8.1.1
  • Once resolved, later calls to resolve or reject are ignored—even if the adopted thenable has not settled. section 8.1.1
  • People sometimes use “resolved” colloquially to mean settled or fulfilled; the terms are not interchangeable here. section 8.1.1
Listing 8.2 Resolving promises with other promises
const fulfilledPromise = Promise.resolve("fulfilled"); #A
const rejectedPromise = Promise.reject(new Error("rejected")); #A
 
const promise1 = new Promise((resolve) => resolve(fulfilledPromise));
const promise2 = new Promise((resolve) => resolve(rejectedPromise));

promise1.then((value) => { #B
  console.log(`promise1 was fulfilled with value "${value}"`); #B
}); #B
promise2.then(undefined, (reason) => { #C
  console.log(`promise2 was rejected with reason "${reason}"`); #C
}); #C

Compare how resolving with fulfilled and rejected promises makes each new promise adopt the corresponding outcome. section 8.1.1

How Secrets of the JavaScript Ninja, Third Edition covers it

How deep it goes
Defines resolution and explains promise and thenable adoption, but does not detail the full resolution procedure.
Examples
Uses promises adopting fulfilled or rejected promises and a thenable that never invokes its callbacks.
What it assumes
Assumes familiarity with promises and thenables while distinguishing resolution from settlement.
What you can do after
Evaluate whether a resolved promise is settled by checking whether it has fulfilled or rejected.
How it connects
Connects promises with thenables, fulfillment, rejection, and settlement.

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.