Class LocalExecutor

Runs journeys in this process, one at a time, with no persistence: a journey lives only as long as the call to run that runs it. It accepts synchronous and asynchronous steps and reporters alike, and waits for whatever they return.

For each journey it makes a new dispatcher with its dispatcher factory, the default one unless it is given another, and keeps nothing of the journey once run settles. Several executors run journeys in parallel.

import assert from "node:assert/strict";
import { LocalExecutor } from "itinera/executor";
import { type Outcome, Step } from "itinera/step";
import { RecordingReporter } from "itinera/testing";
import { Workflow } from "itinera/workflow";

class Ship extends Step {
override run(): Outcome {
return this.succeed();
}
}

class Orders extends Workflow {}

export default (async () => {
const orders = Orders.builder()
.name("orders")
.step(Ship.builder("ship"))
.build();
const recorder = new RecordingReporter();
const executor = new LocalExecutor();

const result = await executor.run(
orders.instance({}, { reporters: [recorder] }),
);

assert.ok(result.isSucceeded());
assert.deepEqual(recorder.path, [
"ship attempt 1 succeeded",
"journey succeeded",
]);
})();

Index

  • Runs the one journey of instance, and resolves to its result: it succeeded or failed, with its data bag, or it was aborted. Nothing that happens in the journey rejects.

    Parameters

    Returns Promise<JourneyResult>

    Refusal, as a rejection, before any journey and any event: when the executor is running a journey, the instance was handed to run before, its initial data or global metadata is refused, or the dispatcher factory, the dispatcher or a reporter fails before the journey starts.

    TypeError, as a rejection, when instance was not made by instance() on a workflow object, which only a cast lets through.