import type { AtomType } from "../Mutables/atom/atom"; export type TaskStatus = "pending" | "running" | "success" | "failed" | "cancelled"; export type Task = { /** Auto-incrementing integer, unique within this taskAction instance. */ id: number; /** The value originally passed to add(). */ input: TInput; status: TaskStatus; result: { data: TOutput | null; error: Error | null; }; /** * Live AbortController while the task is running. * For ZeroPromise-based callbacks this is a synthetic wrapper that * routes .abort() to zp.cancel() and exposes zp.signal. * null when the task is pending, settled, or cancelled. */ abortController: AbortController | null; }; export type TaskActionType = { /** * Append one task or an array of tasks to the list. * * If the session is currently running and a concurrency slot is free the * task(s) are launched immediately. Otherwise they sit as "pending" until * the next available slot (or until start() is called). */ add(input: TInput | TInput[]): void; /** * Begin (or resume) processing. * * concurrency controls how many tasks run at the same time: * 1 → one at a time (queue / serial mode) [default] * N → up to N tasks concurrently * -1 → all pending tasks at once * * No-op if the session is already running. */ start(concurrency?: number): void; /** * Soft pause — running tasks are allowed to finish, but once the current * batch settles no new tasks are launched. The session transitions to idle * after the last in-flight task settles. Call start() to resume. */ pause(): void; /** * Hard stop — immediately cancels every running task (marks them * "cancelled" and aborts their signal), then transitions to idle. * Pending tasks remain in the list. Call start() to resume. */ stop(): void; /** * Remove one or more tasks by identity. * If a matched task is currently running it is cancelled first. */ delete(task: Task | Task[]): void; /** * stop() + clear the whole task list + add fresh tasks. * Does NOT automatically call start() — the caller decides when to start. */ clearAndAdd(input: TInput | TInput[]): void; /** * add() + start() if not already running. * If already running the tasks are simply appended (and launched immediately * if a slot is free). */ addAndStart(input: TInput | TInput[], concurrency?: number): void; /** * stop() + clearAndAdd() + start() in one call. * Replaces the entire task list and immediately begins processing. */ clearAndStart(input: TInput | TInput[], concurrency?: number): void; /** * Returns true while the session status is "running". * Reads from a reactive atom — reactive when called inside a template or * effect. */ isRunning(): boolean; /** * Reactive progress atom (0 – 100). * * Progress formula per task: * pending → 0 points * running → 0.5 points (picked up = halfway there) * settled → 1 point (success | failed | cancelled) * * progress = (Σ points / total tasks) × 100, rounded to nearest integer. * Returns 0 when the task list is empty. */ progress: AtomType; /** * Atom containing every task regardless of status, in insertion order. * All derived getters and the progress atom derive from this. */ tasks: AtomType[]>; pendingTasks(): Task[]; runningTasks(): Task[]; successTasks(): Task[]; failedTasks(): Task[]; cancelledTasks(): Task[]; __isTaskAction__: true; }; export declare function taskAction(cb: (input: TInput, signal: AbortSignal) => Promise): TaskActionType; //# sourceMappingURL=taskAction.d.ts.map