Job blockers

Make a job wait until other chains complete, and read their outputs when it runs.

A job can wait for other chains: it starts as blocked and becomes pending once every chain it is blocked by has completed.

capture-paymentcompleted
reserve-stockcompleted
ship-orderblocked→pending

A job type declares what it waits for in blockers, a tuple of job type references: blockers: [{ typeName: "capture-payment" }, { typeName: "reserve-stock" }]. client.createChain then takes the chains to wait for in blockers, and TypeScript checks them against the tuple. Create the blockers and the blocked chain in one transaction, so either all of them exist or none do.

When the blocked job runs, job.blockers holds the blocker chains in the same order, each with its typed output, so a blocked job can read what its blockers produced, such as the payment ID. A blocker's chain can be as long as you like: the job waits for its last job to complete.

Below, a worker runs three jobs at once. ship-order has no blockers, so it ships the order straight away, before the payment is captured and the stock is reserved.

Your task: in jobTypes, give ship-order the blockers capture-payment and reserve-stock; then pass the payment and stock chains as blockers when you create the ship-order chain.
esc

Search guides, integrations and every exported symbol.

↑ ↓ to navigate↵ to open