createTask
Creates a Task — one unit of work with a name and a run.fn.
createTask(config)— Returns a Taskconfig.name— Required string used in errors andtask.nameconfig.run.fn— Required function; receivesconfig.run.contextresolved, returns the Task’s value. Sync or asyncconfig.run.context— OptionalSpot, or record or array of Spotsconfig.enabled.fn— Optional function; receivesconfig.enabled.contextresolved, returns a boolean.falseskips the Task. Sync or asyncconfig.enabled.context— OptionalSpot, or record or array of Spotstask.name— Mirror ofconfig.nametask.kind— Literal string"task"task.result— Whatrun.fnreturnstask.status—Spot<"done" | "fail" | "skip">task.error—Spot<unknown>; set when status is"fail"
createTask({ name: "ping", run: { fn: () => "pong" },})
createTask({ name: "fetchUser", run: { context: userId.value, fn: (id) => fetch(`/users/${id}`).then((r) => r.json()), },})
createTask({ name: "loadProfile", run: { context: user.result, fn: (u) => u.profile }, enabled: { context: featureFlag.value, fn: (f) => f.profile },})Status is "fail" when run.fn or enabled.fn throws, "skip" when enabled.fn returns false or any required context is missing, "done" otherwise.