import type { Kernel } from "~/index.js"; import type { InputDispatcher } from "~/index.js"; type RunInContext = (fn: () => TResult) => TResult; /** * Dispatches into the handler app in the async context captured at boot. Identity and * authorization overrides (`withIdentity`, `withoutAuthorization`) live in AsyncLocalStorage, so an * event dispatched from inside one of them would otherwise run its whole request under it. */ export class KernelInputDispatcher implements InputDispatcher.Interface { public constructor( private readonly app: Kernel, private readonly runInBootContext: RunInContext ) {} public dispatch(event: unknown): Promise { return this.runInBootContext(() => this.app.handle(event)); } }