Registration & Execution
An executor must be registered before it can be executed. Postboy offers two registration models: direct function and handler‑based. Both associate the executor’s identity with its implementation.
Once registered, execution is done through postboy.exec(…), which returns the typed result synchronously.
1. Direct function registration
Use ConnectExecutor to register a plain function. This is ideal for lightweight operations or thin wrappers around existing logic.
Registration of a message
Execution of a message
2. Handler‑based registration
For complex operations, place the logic in a dedicated handler class that extends PostboyExecutionHandler<T, E>. Then register it with ConnectHandler.
Handler definition
Registration
Execution
3. Choosing a registration model
Criterion | Direct function ( | Handler class ( |
|---|---|---|
Boilerplate | Minimal | Moderate |
Best for | One‑liners, simple wrappers | Complex logic, multi‑step processes |
Unit testing | Test the function directly | Test the handler class in isolation |
Separation of concerns | Logic lives near registration | Logic isolated in a separate class |
Both models produce the same runtime behaviour. Pick the one that keeps your codebase readable.
4. Infrastructure use‑case
Postboy ships with built‑in executors for bus management. These are registered and executed using the same mechanism.
These infrastructure executors are not special — they follow the same contract and lifecycle as any other executor.
5. Summary
Registration is mandatory; use
ConnectExecutororConnectHandler.Execution is synchronous and returns the typed result immediately.
Choose direct registration for simple logic, handler classes for complex operations.
Infrastructure operations are just regular executors.