import { Result } from "./OptionResult"; import { LooseRecord } from "./types"; export declare class __Future { /** * Creates a new future from its initializer function (like `new Promise(...)`) */ static make: (init: (resolver: (value: A_1) => void) => (() => void) | void) => Future; static isFuture: (value: unknown) => value is Future; /** * Creates a future resolved to the passed value */ static value: (value: A_1) => Future; /** * Converts a Promise to a Future\> */ static fromPromise(promise: Promise): Future>; /** * Turns an array of futures into a future of array */ static all: []>(futures: Futures, propagateCancel?: boolean) => Future<{ [K in keyof Futures]: Futures[K] extends Future ? T : never; }>; /** * Turns an dict of futures into a future of dict */ static allFromDict: >>(dict: Dict) => Future<{ [K in keyof Dict]: Dict[K] extends Future ? T : never; }>; static wait: (ms: number) => Future; static retry: (getFuture: (attempt: number) => Future>, { max }: { max: number; }) => Future>; static concurrent: Future)[]>(array: Futures, { concurrency }: { concurrency: number; }) => Future<{ [K in keyof Futures]: Futures[K] extends () => Future ? T : never; }>; private _state; protected constructor(); /** * Runs the callback with the future value when resolved */ onResolve(func: (value: A) => void): void; /** * Runs the callback if and when the future is cancelled */ onCancel(func: () => void): void; /** * Cancels the future */ cancel(): void; /** * Returns the Future containing the value from the callback * * (Future\, A => B) => Future\ */ map(func: (value: A) => B, propagateCancel?: boolean): Future; then(func: (value: A) => void): this; /** * Returns the Future containing the value from the callback * * (Future\, A => Future\) => Future\ */ flatMap(func: (value: A) => Future, propagateCancel?: boolean): Future; /** * Runs the callback and returns `this` */ tap(this: Future, func: (value: A) => unknown): Future; /** * For Future>: * * Runs the callback with the value if ok and returns `this` */ tapOk(this: Future>, func: (value: A) => unknown): Future>; /** * For Future>: * * Runs the callback with the error if in error and returns `this` */ tapError(this: Future>, func: (value: E) => unknown): Future>; /** * For Future>: * * Takes a callback taking the Ok value and returning a new result and returns a future resolving to this new result */ mapOkToResult(this: Future>, func: (value: A) => Result, propagateCancel?: boolean): Future>; /** * For Future>: * * Takes a callback taking the Error value and returning a new result and returns a future resolving to this new result */ mapErrorToResult(this: Future>, func: (value: E) => Result, propagateCancel?: boolean): Future>; /** * For Future>: * * Takes a callback taking the Ok value and returning a new ok value and returns a future resolving to this new result */ mapOk(this: Future>, func: (value: A) => B, propagateCancel?: boolean): Future>; /** * For Future>: * * Takes a callback taking the Error value and returning a new error value and returns a future resolving to this new result */ mapError(this: Future>, func: (value: E) => B, propagateCancel?: boolean): Future>; /** * For Future>: * * Takes a callback taking the Ok value and returning a future */ flatMapOk(this: Future>, func: (value: A) => Future>, propagateCancel?: boolean): Future>; /** * For Future>: * * Takes a callback taking the Error value and returning a future */ flatMapError(this: Future>, func: (value: E) => Future>, propagateCancel?: boolean): Future>; /** * Converts the future into a promise */ toPromise(): Promise; /** * For Future>: * * Converts the future into a promise (rejecting if in Error) */ resultToPromise(this: Future>): Promise; } export declare const Future: typeof __Future; export type Future = __Future;