Class DefaultDispatcher

The dispatcher executors use unless they are given another factory.

It calls its reporters in the order they were added, waiting for each before the next. When a reporter fails, the event stops there and the failure is passed on, except for journey_aborted, which goes on to every reporter past a failure, then passes on the first. Each entry of global metadata reaches the reporters in the same order, and stops at the first that fails.

import assert from "node:assert/strict";
import type { Event } from "itinera/event";
import { DefaultDispatcherFactory, type Reporter } from "itinera/report";
import { type PlainValue } from "itinera/value";

class Keeping implements Reporter {
readonly entries: string[] = [];

receiveGlobalMetadata(key: string, value: PlainValue): void {
this.entries.push(`${key}=${JSON.stringify(value)}`);
}

report(event: Event): void {
this.entries.push(event.kind);
}
}

export default (async () => {
const first = new Keeping();
const second = new Keeping();
const dispatcher = new DefaultDispatcherFactory().create();
dispatcher.add(first);
dispatcher.add(second);
await dispatcher.setGlobalMetadata("tenant", "acme");
assert.deepEqual(first.entries, ['tenant="acme"']);
assert.deepEqual(second.entries, ['tenant="acme"']);
})();

Implements

Index