race(values) {
    let deferred;
    /** @type {[...T]} */
    // @ts-expect-error filled by the loop
    const cachedValues = [];
    const C = this;
    const result = new C((resolve, reject) => {
      deferred = { resolve, reject };
      for (const value of values) {
        cachedValues.push(value);
        const { settled, deferreds } = getMemoRecord(value);
        if (settled) {
          // If the contender is settled (including primitives), it is safe
          // to call `Promise.resolve(value).then` on it.
          C.resolve(value).then(resolve, reject);
        } else {
          deferreds.add(deferred);
        }
      }
    });

    // The finally callback executes when any value settles, preventing any of
    // the unresolved values from retaining a reference to the resolved value.
    return result.finally(() => {
      for (const value of cachedValues) {
        const { deferreds } = getMemoRecord(value);
        if (deferreds) {
          deferreds.delete(deferred);
        }
      }
    });
  }
Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
or rejected.

Unlike `Promise.race` it cleans up after itself so a non-resolved value doesn't hold onto
the result promise.

@template {readonly unknown[] | []} T
@template {PromiseConstructor} [P=PromiseConstructor]
@this {P}
@param {T} values An iterable of Promises.
@returns {Promise<Awaited<T[number]>>} A new Promise.