Lifecycle
The executor lifecycle covers the full path from registration to the moment the caller receives a result.
1. Registration (one‑time)
Before an executor can be used, its logic must be registered.
This happens once, typically during application bootstrap.
From this point, the bus knows how to handle FormatDateExecutor.
2. Execution call
Any code that needs the operation passes an executor instance to postboy.exec(…).
3. Middleware hooks
Before and after the handler runs, middleware can inspect, block, or augment the execution.
beforeExecute(executor)— can throw to cancel execution.afterExecute(executor, result)— can log, measure, or modify the result.
Middleware does not replace the handler; it only observes the lifecycle.
4. Handler execution
Postboy resolves the registered logic (function or handler class) and passes the executor instance to it.
The handler performs the actual work and returns the typed result.
5. Result returned
The result is passed back to the caller synchronously.
Full lifecycle in sequence
Key points
Registration is separate from execution.
The lifecycle is synchronous from the caller’s point of view.
Middleware is the only place where cross‑cutting concerns (logging, validation) belong.
The handler remains a pure unit of work, testable in isolation.