Lingua-e
JavaScript

What is a Promise Resolve Called Twice?

← Errors

Calling resolve() or reject() more than once inside a Promise constructor is silently ignored. A Promise can only be settled once. This is not an error per se, but a common source of subtle bugs where developers expect multiple values or callbacks from a single promise.

Why it happens

  • A callback-based API calls its callback more than once, and each call triggers resolve.
  • Both a success path and an error path call resolve instead of one calling reject.
  • An event listener inside a Promise constructor fires multiple times.

Examples

JavaScript

Code that triggers the error

const p = new Promise((resolve, reject) => {
  resolve("first");
  resolve("second"); // silently ignored
  reject(new Error("oops")); // also silently ignored
});
const val = await p;
console.log(val); // "first"

Error output

first
// No error is thrown. The second resolve and the reject are silently ignored.

How to fix it

Promises model a single future value. For multiple values, use an EventEmitter, RxJS Observable, or an async generator. Ensure that each code path inside the Promise executor calls either resolve or reject exactly once, then returns.

Fixed code

// Promise state is immutable once settled.
// If you need multiple values, use an event emitter or async generator.
async function* stream() {
  yield "first";
  yield "second";
}
for await (const val of stream()) {
  console.log(val);
}

Related errors

Ready to practice your English at work?

Lingua-e has interactive exercises built around real developer conversations: standups, code reviews, retrospectives, and more. Practice until it comes naturally.

Try Lingua-e for free