withResolvers.ts
utils/withResolvers.ts
No strong subsystem tag
14
Lines
444
Bytes
1
Exports
0
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file is one piece of the larger system. Its name, directory, imports, and exports show where it fits. Start by reading the exports and related files first.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with general runtime concerns. It contains 14 lines, 0 detected imports, and 1 detected exports.
Important relationships
Detected exports
withResolvers
Keywords
promiseresolverejectwithresolversnodevoidpolyfilles2024packagejson
Detected imports
- No import paths detected.
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
/**
* Polyfill for Promise.withResolvers() (ES2024, Node 22+).
* package.json declares "engines": { "node": ">=18.0.0" } so we can't use the native one.
*/
export function withResolvers<T>(): PromiseWithResolvers<T> {
let resolve!: (value: T | PromiseLike<T>) => void
let reject!: (reason?: unknown) => void
const promise = new Promise<T>((res, rej) => {
resolve = res
reject = rej
})
return { promise, resolve, reject }
}