Continuing a chain
Hand a chain from one job to the next with continueWith, pick the next job at runtime, and let the last job's output complete it.
A chain can run more than one job: a job hands the chain on to the next job type, and the chain completes with the output of its last job.
A handler ends its job through applyJobOutcome in one of two ways: with an output, which completes the chain, or with continueWith, the next typeName and that job's input, which creates the next job in the same transaction as the one that finished. The chain keeps its identity across jobs, so client.awaitChain resolves once the last job completes, with that job's output.
Types spell this out in defineJobTypes. A job type lists the types it may continue with in continueWith instead of declaring an output, and a type reachable only through a chain drops entry, so createChain refuses it. The compiler then checks every continueWith against the declared type and its input.
A job can also choose its next job at runtime. List every type it may continue with as a union, continueWith: { typeName: "page-on-call" | "queue-for-support" }, and pass the one you picked to continueWith; TypeScript checks the input against the type you chose, and only that job is created.
jobTypes, give provision-account a continueWith of send-welcome-email instead of an output, and remove entry from send-welcome-email; then pass continueWith to applyJobOutcome in the provision-account handler.Related guides
- Chain patterns: linear, branched, loop and go-to continuations.