Appearance
Function: runJobsSequentially()
ts
function runJobsSequentially<T>(
ctx: Context,
jobs: T,
options?: RunJobsSequentiallyOptions): JobResults<T>;Defined in: src/jobs/runJobs.ts:327
Run jobs sequentially, passing each result to the next job.
Type Parameters
| Type Parameter |
|---|
T extends JobList |
Parameters
| Parameter | Type | Description |
|---|---|---|
ctx | Context | Context to run the jobs in. |
jobs | T | Array of jobs to run in order. |
options? | RunJobsSequentiallyOptions | Callback options. |
Returns
JobResults<T>
Array of results in the same order as the jobs.
Example
ts
const jobs = [
{title: 'Pick base', handler: async () => 'sourdough'},
{title: 'Add topping', handler: async (ctx, base) => `${base} + pepperoni`},
{title: 'Bake', handler: async (ctx, pizza) => `${pizza} (baked)`},
];
const results = await runJobsSequentially(ctx, jobs, {onUpdate: console.log});
console.log(results);
// [{title: 'Pick base', result: 'sourdough'}, ...]Remarks
To keep going when a job fails, wrap the handler body in try/catch.