Context
currentJob() — the running task's job context.
currentJob() — the running task's job context.
import { currentJob } from "@byteveda/flexiq";
const job = currentJob(); // JobContext | undefinedReturns the running task's context, or undefined outside a task. Backed by
AsyncLocalStorage, so it survives await boundaries within the task.
JobContext| Member | Type | Description |
|---|---|---|
jobId | string | The running job's id. |
signal | AbortSignal | Aborted on cancel or timeout — pass to fetch/streams. |
setProgress(n) | (0–100) => void | Report progress for inspection / dashboard. |
publish(value) | (unknown) => void | Emit a partial result for queue.stream (JSON-serializable). |
queue.task("download", async (url: string) => {
const job = currentJob();
const res = await fetch(url, { signal: job?.signal });
job?.setProgress(100);
return res.text();
});See Cancellation for the cooperative cancellation flow.
useResourceimport { useResource } from "@byteveda/flexiq";
const db = await useResource<Pool>("db"); // inside a running taskResolves a registered resource by
name against the current job's scope. Also AsyncLocalStorage-backed, so it
works across await boundaries. Throws if called outside a task.