mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-18 07:21:33 +00:00
16 lines
433 B
TypeScript
16 lines
433 B
TypeScript
export type Deferred<T = void> = {
|
|
promise: Promise<T>;
|
|
resolve: (value: T | PromiseLike<T>) => void;
|
|
reject: (reason?: unknown) => void;
|
|
};
|
|
|
|
type PromiseConstructorWithResolvers = PromiseConstructor & {
|
|
withResolvers<T>(): Deferred<T>;
|
|
};
|
|
|
|
const promiseWithResolvers = Promise as PromiseConstructorWithResolvers;
|
|
|
|
export function createDeferred<T = void>(): Deferred<T> {
|
|
return promiseWithResolvers.withResolvers<T>();
|
|
}
|