Skip to content

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

ParameterTypeDescription
ctxContextContext to run the jobs in.
jobsTArray of jobs to run in order.
options?RunJobsSequentiallyOptionsCallback 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.

Matterway Assistant SDK Documentation