import type { Future } from "./future.ts"; import { fromPromise } from "./from.ts"; /** * Provides resolvers for manually controlling the resolution of a future. * @returns An object containing the Future, the resolve and reject methods. */ export function withResolvers(): FutureWithResolvers { const { promise, resolve, reject } = Promise.withResolvers(); const future = fromPromise(promise); return { future, resolve, reject, }; } export interface FutureWithResolvers extends Omit, "promise"> { future: Future; resolve: (value: TReturn | PromiseLike) => void; reject: (reason?: unknown) => void; }