Last active
December 7, 2020 20:55
-
-
Save lcanady/8b0d7774f52d5ed024a38038c74bbbc2 to your computer and use it in GitHub Desktop.
A Middleware engine written in typescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Declare a new middleware pipeline. | |
| * @param middlewares A list of middlewares to add to the pipeline on | |
| * instantiation. | |
| */ | |
| export function pipeline<T>(...middlewares: Middleware<T>[]): Pipe<T> { | |
| const stack: Middleware<T>[] = middlewares; | |
| /** | |
| * Add middlewares to the pipeline. | |
| * @param middlewares A list of middlewares to add to the current | |
| * pipeline. | |
| */ | |
| const use: Pipe<T>["use"] = (...middlewares) => { | |
| stack.push(...middlewares); | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment