pub struct Next { /* private fields */ }Expand description
Opaque continuation passed to a Middleware. Calling Next::run
proceeds to the next middleware in the chain or to the Terminal if
the chain is exhausted.
The middleware chain is held as a shared Arc<[_]> walked with an index
cursor, so advancing the pipeline is a reference-count bump rather than a
per-dispatch allocation of the chain.
Implementations§
Source§impl Next
impl Next
Sourcepub fn new(
middlewares: impl Into<Arc<[Arc<dyn DynMiddleware>]>>,
terminal: Arc<dyn Terminal>,
) -> Self
pub fn new( middlewares: impl Into<Arc<[Arc<dyn DynMiddleware>]>>, terminal: Arc<dyn Terminal>, ) -> Self
Builds a new Next from a chain of middlewares and a terminal.
Middlewares are executed in the order they appear: the first one wraps
the second, which wraps the third, and so on. The chain accepts any
Into<Arc<[_]>>, so a freshly built Vec or a pre-shared Arc<[_]>
(cloned once per dispatch as a reference-count bump) both work.
Sourcepub async fn run(
self,
envelope: &MessageEnvelope,
ctx: &HandlerContext,
) -> Result<BoxOutput, HexeractError>
pub async fn run( self, envelope: &MessageEnvelope, ctx: &HandlerContext, ) -> Result<BoxOutput, HexeractError>
Advances the pipeline by one step.
The context’s cancellation token is observed before each step: a
middleware that cancels the token short-circuits the rest of the
chain at the next Next::run call, and the Terminal is never
reached. A step that is already executing is not interrupted.
§Errors
Returns HexeractError::Cancelled if the context’s cancellation
token fired, or the HexeractError produced by the next middleware
in the chain or by the Terminal when the chain is exhausted.