@hyperfrontend/immutable-api-utils/built-in-copy/promise

promise

Locked, prototype-pollution-resistant copy of the global Promise constructor and its statics.

The Promise constructor is wrapped in a createPromise factory and its statics (resolve, reject, all, race, allSettled, any, withResolvers) are captured at module-load time and frozen into a tamper-proof namespace, so async control flow keeps working even if the global Promise is later patched. Effective only when imported before any untrusted code has had a chance to mutate the prototype chain.

API Reference

ƒ Functions

§function

createPromise<T>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: unknown) => void) => void): Promise<T>

(Safe copy) Creates a new Promise using the captured Promise constructor. Use this instead of new Promise().

Parameters

NameTypeDescription
§executor
(resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: unknown) => void) => void
The executor function.

Returns

Promise<T>
A new Promise instance.

Variables

§type

Promise

(Safe copy) Namespace object containing all Promise factory functions. Note: Importing this imports all methods in this namespace (no tree-shaking).
§type

promiseAll

(Safe copy) Returns a Promise that resolves when all promises resolve.
§type

promiseAllSettled

(Safe copy) Returns a Promise that resolves when all promises settle.
§type

promiseAny

(Safe copy) Returns a Promise that resolves with the first fulfilled promise.
§type

promiseRace

(Safe copy) Returns a Promise that resolves/rejects with the first settled promise.
§type

promiseReject

(Safe copy) Returns a Promise that rejects with the given reason.
§type

promiseResolve

(Safe copy) Returns a Promise that resolves with the given value.
§type

promiseWithResolvers

(Safe copy) Creates a Promise along with its resolve and reject functions. Note: Available only in ES2024+ environments.