mirror of
https://github.com/stackblitz/bolt.new
synced 2024-11-27 14:32:46 +00:00
20 lines
416 B
TypeScript
20 lines
416 B
TypeScript
export function withResolvers<T>(): PromiseWithResolvers<T> {
|
|
if (typeof Promise.withResolvers === 'function') {
|
|
return Promise.withResolvers();
|
|
}
|
|
|
|
let resolve!: (value: T | PromiseLike<T>) => void;
|
|
let reject!: (reason?: any) => void;
|
|
|
|
const promise = new Promise<T>((_resolve, _reject) => {
|
|
resolve = _resolve;
|
|
reject = _reject;
|
|
});
|
|
|
|
return {
|
|
resolve,
|
|
reject,
|
|
promise,
|
|
};
|
|
}
|