Repository navigation
Changed
FlexJob for intermediate publications
Added FlexJob<Result, Update>, a Job that can publish intermediate values while it is running.
A FlexJob retains the ordinary Job lifecycle and result semantics while exposing a bounded channel for intermediate publications. Its body can call publish(value) multiple times, and consumers can receive those values with receive().
Unlike a handoff, publication is one-way: publish() delivers or stores the value and the body continues without waiting for the consumer to acknowledge it.
import { FlexJob } from "@tiberjs/runner";
type Update = { phase: "started" | "processed" };
const job = new FlexJob<string, Update>(async (publish) => {
publish({ phase: "started" });
await doWork();
publish({ phase: "processed" });
return "finished";
});
job.start();
const update = await job.receive(); // { done: false, value: Update }, or channel completion
const result = await job.result(); // { ok: true, value: "finished" }, or { ok: false, error }await job and job.result() retain the ordinary Job contract and wait for the body, descendants, and finalizers to settle.
HandoffJob and Handoff deprecated
HandoffJob and Handoff are now deprecated. Use FlexJob when a Job needs to expose intermediate values before completion.
Existing handoffs retain their one-shot, two-way rendezvous semantics. In particular, offer() suspends the body until the consumer calls resume(). FlexJob intentionally does not provide this acknowledgement mechanism: publish() does not suspend for consumption and there is no corresponding resume().
Code that used a handoff only to expose an intermediate value can generally migrate from offer()/receive() to publish()/receive().
Code that depends on the acknowledgement returned by resume() should not mechanically replace offer() with publish(). Keep that acknowledgement exchange explicit in the Job body instead.