import { CancellablePromise, PromiseWithState } from './types'; import { promiseTry } from './helpers'; /** * Create a cancellable delay promise. * * @example * const delay = async.delay(1000); * // Later... * delay.cancel(); // Cancel the delay */ export declare function delay(ms: number, resolved?: T): CancellablePromise; /** * Wraps a synchronous or async function to always return a Promise. * Ensures async execution even for synchronous functions. * * This is the same utility used internally for dispatching handlers. * * @example * const promise = async.invoke(() => { * // Sync or async code * return someValue; * }); */ export declare const invoke: typeof promiseTry; /** * Get the state of a promise or synchronous function execution. * Returns a PromiseWithState that has a `.state` property tracking its status. * * @overload * @param promise - The promise to get the state of. * @returns The promise with state tracking. * * @overload * @param fn - A function to execute synchronously. * @returns A PromiseWithState based on execution result: * - If returns value → status: "fulfilled", Promise.resolve(value) * - If throws Error → status: "rejected", Promise.reject(error) * - If throws Promise (Suspense) → status: "pending", Promise resolved to thrown promise * * @example * // With promise * const pws = async.state(fetch('/api/data')); * console.log(pws.state.status); // "pending" | "fulfilled" | "rejected" * * @example * // With function - useful for Suspense patterns * const pws = async.state(() => { * const cache = getFromCache(key); * if (!cache) throw fetchAndCache(key); // throws promise for Suspense * return cache; * }); * console.log(pws.state.status); // "pending" if promise thrown, "fulfilled" if cached */ export declare function state(promise: PromiseLike): PromiseWithState; export declare function state(fn: () => T): PromiseWithState>; /** * Convert a value or parameterless function to a Promise. * Handles: PromiseLike, sync values, functions returning either. * * @example * toPromise(42) // Promise.resolve(42) * toPromise(Promise.resolve(42)) // Promise.resolve(42) * toPromise(() => 42) // Promise.resolve(42) * toPromise(() => fetchData()) // fetchData() promise * toPromise(thenable) // Promise wrapping thenable */ export declare function toPromise(value: T | (() => T)): Promise>; //# sourceMappingURL=utils.d.ts.map