call method
Executes the pipeline with the given input.
This method:
- Builds the middleware chain in reverse order (right-to-left)
- Each middleware wraps the previous handler
- Calls the complete chain with the input
The chain is built as: mw1(mw2(mw3(...(core_handler))))
where middleware are ordered as they were added via use.
Returns a Future that resolves when the entire pipeline completes. If any middleware throws an exception, it propagates through the Future.
Parameters:
input: The value to process through the pipeline
Returns: A Future containing the processed value
Example:
final pipeline = Pipeline<int>();
pipeline.use((next) => (value) async => await next(value * 2));
final result = await pipeline(5); // Returns 10
Implementation
Future<T> call(T input) {
var handler = _handler<T>;
// Build chain right to left: first middleware ends up outermost
for (final mw in _middlewares.reversed) {
final next = handler;
handler = mw(next);
}
return handler(input);
}