co-compose
Version:
AdonisJS and Koa style middleware layer with ability to run parallel middleware
44 lines (43 loc) • 1.37 kB
TypeScript
import { Executor, FinalHandler, FinalHandlerArgs } from './Contracts';
/**
* Runnable to execute an array of functions in sequence. The queue is
* advanced only when the current function calls `next`.
*
* @example
* ```js
* const runner = new Runnable([async function fn1 (params, next) {
* }])
* ```
*/
export declare class Runnable {
private list;
private index;
private params;
private executorFn;
private registeredFinalHandler;
constructor(list: any[]);
/**
* Invoke one middleware at a time. Middleware fns will be executed
* recursively until `next` is invoked.
*
* If one method doesn't call `next`, then the chain will be finished
* automatically.
*/
private invoke;
/**
* Final handler to be executed, when chain ends successfully
*/
finalHandler(fn: FinalHandler, args: FinalHandlerArgs): this;
/**
* Define custom resolver, which is invoked for all the middleware.
* If this method is defined, then default executor is not called
* and it's the responsibility of this method to call the
* middleware and pass params to it
*/
executor(fn: Executor): this;
/**
* Start the middleware queue and pass params to it. The `params`
* array will be passed as spread arguments.
*/
run(params: any[]): Promise<void>;
}