compose static method
Composes a list of middlewares and a final handler into a single Handler.
This pre-builds the execution chain for better performance.
Implementation
static Handler compose(List<Middleware> middlewares, Handler handler) {
return (Context ctx) {
int index = 0;
Future<Response> next() async {
if (index < middlewares.length) {
return await middlewares[index++](ctx, next);
}
return await handler(ctx);
}
return next();
};
}