liveBook · Manning

Executor

As explained in Secrets of the JavaScript Ninja, Third Edition

An executor is the callback passed to a promise constructor that runs immediately and receives functions for resolving or rejecting the promise.

A promise executor is the callback passed to the Promise constructor. It runs immediately when the promise is created and receives resolve and reject functions, which control how the promise settles. section 8.1.1

const promise = new Promise((resolve, reject) => {
  // code that calls resolve or reject eventually...
});

The constructor syntax shows the executor receiving resolve and reject. section 8.1.1

Calling resolve with a normal value fulfills the promise; calling reject or throwing from the executor rejects it. A promise settles only once. Resolving with a thenable makes the promise follow that thenable’s outcome. section 8.1.1

How Secrets of the JavaScript Ninja, Third Edition covers it

How deep it goes
Explains immediate execution, settlement rules, thrown errors, and thenable resolution without detailing internal APIs.
Examples
Uses a Promise constructor callback and examples that resolve with fulfilled or rejected promises.
What you can do after
Understand how executor calls and thrown errors determine a promise’s settlement.
How it connects
Connects promise executors to promises, resolve and reject functions, and thenables.

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.