Class

DecafHandlerExecutor

DecafHandlerExecutor()

Constructor

# new DecafHandlerExecutor()

The DecafHandlerExecutor class is responsible for orchestrating and executing a sequence of request handlers. Each handler receives the same request-scoped context, allowing coordinated processing such as authentication, metadata extraction, auditing, and custom pipeline behavior. Handlers are injected via the DECAF_HANDLERS token, ensuring extensibility and loose coupling.

Executes all registered DecafRequestHandler instances for the current request, providing them with a shared DecafRequestContext.

sequenceDiagram participant Client participant Executor participant HandlerA participant HandlerB Client->>Executor: exec(req) Executor->>HandlerA: handle(context, req) HandlerA-->>Executor: completed Executor->>HandlerB: handle(context, req) HandlerB-->>Executor: completed Executor-->>Client: processing finished

View Source request/DecafHandlerExecutor.ts, line 15

Example
```ts
// Example handler:
class AuthHandler implements DecafRequestHandler {
  async handle(context: DecafRequestContext, req: Request) {
    const token = req.headers["authorization"];
    const result = MyService.doSomething(token);
    context.set("my-key", result);
  }
}

// Executor usage in a request:
await executor.exec(request);
// All handlers will run in sequence
```