Skip to content

promise-never-settles ​

A new Promise whose executor has a path that neither calls resolve or reject nor hands them to something that will. On by default, as an error.

Why: a promise that never settles has no error, no timeout and no stack trace: whatever awaits it simply stops. A request handler holds its connection, a shutdown waits for a flush, a test hangs until the runner kills it. if (flag) resolve(value) with no else, or a catch that only logs, is all it takes, and tsc strict accepts both.

❌ Rejected: when ready is false, every caller waits forever

ts
import { PropagateError } from "@evobug_com/safe-ts-std/result";

export class NotReady extends PropagateError {}

export function whenReady(ready: boolean): Promise<number> {
  return new Promise((resolve) => {
    if (ready) resolve(1);
  });
}

✅ Accepted: a Result, so the other path has a value too

✓ Accepted0 diagnostics
ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { err, type Result } from "@evobug_com/safe-ts-std/result";

export type WaitError = Enum<{ NotReady: {} }>;
export const WaitError = constructors<WaitError>();

export function whenReady(ready: boolean): Promise<Result<number, WaitError>> {
  return new Promise((resolve) => {
    if (ready) resolve(1);
    else resolve(err(WaitError.NotReady()));
  });
}
ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { err, type Result } from "@evobug_com/safe-ts-std/result";

export type WaitError = Enum<{ NotReady: {} }>;
export const WaitError = constructors<WaitError>();

export function whenReady(ready: boolean): Promise<Result<number, WaitError>> {
  return new Promise((resolve) => {
    if (ready) resolve(1);
    else resolve(err(({ tag: "NotReady" } satisfies WaitError as WaitError)));
  });
}

✅ Also accepted: reject on the other path

✓ Accepted0 diagnostics
ts
import { PropagateError } from "@evobug_com/safe-ts-std/result";

export class NotReady extends PropagateError {}

export function whenReady(ready: boolean): Promise<number> {
  return new Promise((resolve, reject) => {
    if (ready) resolve(1);
    else reject(new NotReady("not ready"));
  });
}

Handing resolve on counts: to a timer (setTimeout(resolve, ms)), a listener (emitter.once("done", resolve), el.addEventListener("load", () => resolve(), { once: true })), any other function, or stored where something settles it later (a map of pending calls).

✅ Accepted: handed to whoever settles it later

✓ Accepted0 diagnostics
ts
export function delay(ms: number): Promise<void> {
  return new Promise((resolve) => {
    setTimeout(resolve, ms);
  });
}

export function loaded(image: HTMLImageElement): Promise<void> {
  return new Promise((resolve) => {
    image.addEventListener("load", () => resolve(), { once: true });
  });
}

What counts ​

An every-path question on the executor's own body (how the checker follows paths): on every path to its end, resolve or reject is

  • called;
  • handed on: an argument of a call, the value of an assignment, a property, an element, a return, a declarator (const done = resolve). Looking at it (void reject, typeof resolve, a comparison) isn't;
  • used by a function that is itself handed to a call. Where the call says the function runs once, later (setTimeout, queueMicrotask, requestAnimationFrame, .then, .catch, .finally, once, addEventListener(..., { once: true })), that function is asked the same question: a timer whose callback settles on one path only is reported. Where it runs any number of times (setInterval, addEventListener, on), using resolve at all counts: a later call may settle. A function handed to a call the checker doesn't know counts too.

A path that ends with an exception is fine: an executor that throws rejects its promise. new Promise(() => {}), a promise that never settles written on purpose (a test of a hang), isn't reported.

How it relates to pending-without-close ​

pending-without-close follows resolve / reject once they are kept in a collection: settled from message events, but by nothing when the channel closes. This rule takes "stored in a map" as handed on and stops there, so the two never report the same promise: this one asks whether the executor lets go of its resolvers on every path, that one whether whoever holds them will ever use them.

What the rule can't see ​

  • An executor that isn't written in place (new Promise(executor)), or whose parameters are destructured.
  • Whether whoever gets resolve calls it. A function of the project or a package that is handed resolve is trusted, and so is a listener for an event that never comes.
  • A loop that never ends inside the executor, and a path that settles only after an await inside an async executor that rejects (the rejection is dropped: see promise-as-value).

MIT OR Apache-2.0 · Docs by Gemini 4 Neon Extra