bolt.new/packages/bolt/app/utils/promises.ts

20 lines
416 B
TypeScript
Raw Normal View History

2024-07-10 16:44:39 +00:00
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,
};
}