composeMiddleware<T extends TriggerContext<TriggerRequest, TriggerResponse>> function
Handler<T>
composeMiddleware<
T extends TriggerContext<TriggerRequest, TriggerResponse>>( - List<Handler<T>> handlers,
- T converter(
- T ctx,
- Handler<T> next
)
)
Implementation
Handler<T> composeMiddleware<T extends TriggerContext>(
List<Handler<T>> handlers,
T Function(T ctx, Handler<T> next) converter) =>
(T ctx) async {
final Handler<T> composedHandler = handlers.reversed
.fold((ctx) async => ctx, (nextHandler, currHandler) {
return (ctx) => currHandler(converter(ctx, nextHandler));
});
return await composedHandler(ctx);
};