import { b as CLAIM, p as MaybeReactive, w as SEED } from "../children-s3nFjpLA.mjs"; import { ComputedPromise } from "./promise.mjs"; //#region src/utilities/async.d.ts /** @internal Hydrate cleanup: execute deferred runs no claim resolved. */ declare function flushDeferredAsyncRuns(): void; /** Shape of the async function driven by {@link Async} / {@link async}. */ type Fn = (input: TInput) => Promise; /** * Reactive wrapper around an async function. Exposes the current run as * reactive signals (`state`, `value`, `reason`, `result`, `pending`) and * lets you `run`/`start`/`stop` the underlying task imperatively. * * Trigger choice: `start()` tracks the body and re-runs when its parameter * signals change — right for "fetch X whenever `id` changes". `run()` is * one-shot and untracked — right for externally-driven loads (intersection, * click, form submit), especially when the body writes to the same signals * it reads (`start()` would cascade). * * Prefer the {@link async} factory — it returns an `Async` that is also * callable as a signal (`op()` === `op.result`), which is what most call * sites want. Use this class directly only when you need the object form. * * @example * ```ts * import { Async } from "elements-kit/utilities/async"; * * const loader = new Async(fetchUser); * loader.run("alice"); * effect(() => { * if (loader.state === "fulfilled") console.log(loader.value); * }); * ``` */ declare class Async { #private; get fn(): Fn; set fn(fn: MaybeReactive>); get raw(): ComputedPromise; get pending(): boolean; get state(): "idle" | "pending" | "fulfilled" | "rejected"; get value(): TOutput | undefined; get reason(): unknown; get result(): unknown; then(onfulfilled?: ((value: TOutput | undefined) => TResult1 | PromiseLike) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike) | null): Promise; catch(onrejected?: ((reason: unknown) => TResult | PromiseLike) | null): Promise; finally(onfinally?: (() => void) | null): Promise; /** * @internal Hydration seeding — delegates to the current operation's * `ReactivePromise`. See `ReactivePromise[SEED]`. */ [SEED](value: unknown): void; /** * @internal Hydrate claim protocol. A server record seeds the state and * discards any deferred run — the fetcher never executes. No record means * the deferred run executes now. */ [CLAIM](record: { value: unknown; } | undefined): void; constructor(fn: MaybeReactive>); /** * Runs the async function once with the given input, stopping any currently active * and register cleanup effects. */ run(...args: TInput extends undefined ? [] : [input: TInput]): this; /** * Stops the current async operation and run cleanup effects. */ stop(): this; [Symbol.dispose](): void; /** * Starts a new reactive async operation, stopping any currently active one. */ start(...args: TInput extends undefined ? [] : [input: TInput]): this; } /** @internal Cross-instance-safe `Async` detection. */ declare function isAsyncLike(value: unknown): value is Async; /** * Create an {@link Async} that is also callable as a signal: invoking it * (with no args) reads the current `result`, so it drops into any reactive * context that expects a zero-arg getter. * * @example * ```ts * import { async } from "elements-kit/utilities/async"; * * const load = async((id: string) => fetch(`/u/${id}`).then(r => r.json())); * load.run("alice"); * * // Read as a signal — subscribes to result changes * effect(() => console.log(load())); * await load; // Await the current run — works like a normal promise * ``` */ declare function async(fn: MaybeReactive<(input: TInput) => Promise>): Async & ((...args: any[]) => TOutput | undefined); //#endregion export { Async, Fn, async, flushDeferredAsyncRuns, isAsyncLike };