Cancellation
Cooperative cancellation via AbortSignal, plus progress reporting.
Cancellation is cooperative. A running task reads its context via
currentJob() and watches the AbortSignal:
import { currentJob } from "@byteveda/flexiq";
queue.task("download", async (url: string) => {
const { signal } = currentJob() ?? {};
const res = await fetch(url, { signal });
return res.text();
});
queue.requestCancel(jobId); // aborts the running task's signalrequestCancel(id) flips the cancel flag for a running job; the worker
aborts the signal so signal-aware work (fetch, streams) unwinds. A task that
ignores the signal runs to completion.
queue.cancelJob(id); // cancels a still-pending job before it startsA task can report progress 0–100 through its context:
queue.task("export", async () => {
const job = currentJob();
for (let i = 0; i < 100; i++) {
await step(i);
job?.setProgress(i + 1);
}
});Progress surfaces on the dashboard and via inspection.
currentJob() is backed by AsyncLocalStorage, so it works across await
boundaries inside the task. It returns undefined outside a running task.