import type { Readable } from "svelte/store"; export interface AsyncStateReturn { state: Readable; is_ready: Readable; is_loading: Readable; error: Readable; execute: (delay?: number, ...args: any[]) => Promise; } export interface AsyncStateOptions { /** * Delay for executing the promise. In milliseconds. * * @default 0 */ delay?: number; /** * Execute the promise right after the function is invoked. * Will apply the delay if any. * * When set to false, you will need to execute it manually. * * @default true */ immediate?: boolean; /** * Callback when error is caught. */ on_error?: (e: unknown) => void; /** * Sets the state to initialState before executing the promise. * * This can be useful when calling the execute function more than once (for * example, to refresh data). When set to false, the current state remains * unchanged until the promise resolves. * * @default true */ reset_on_execute?: boolean; /** * * An error is thrown when executing the execute function * * @default false */ throw_error?: boolean; } /** * Reactive async state. Will not block your setup function and will trigger changes once * the promise is ready. * * @param promise The promise / async function to be resolved * @param initial_state The initial state, used until the first evaluation finishes * @param options */ export declare function async_state(promise: Promise | ((...args: any[]) => Promise), initial_state: Data, options?: AsyncStateOptions): AsyncStateReturn; export { async_state as asyncState };