add use
method
This commit is contained in:
parent
59dafba982
commit
bb00e1b207
1 changed files with 5 additions and 0 deletions
|
@ -2,6 +2,7 @@ import { ControlFlow, Break, Continue } from "./control_flow"
|
||||||
|
|
||||||
// Typescript lacks shadowing, so code sometimes can be stupid to avoid it
|
// Typescript lacks shadowing, so code sometimes can be stupid to avoid it
|
||||||
|
|
||||||
|
type Mapper<B, C, Bn, Cn> = (inp: Handler<B, C>) => Handler<Bn, Cn>
|
||||||
export type HandlerFn<B, C> = (req: C, next: Endpoint<B, C>) => Promise<ControlFlow<B, C>>
|
export type HandlerFn<B, C> = (req: C, next: Endpoint<B, C>) => Promise<ControlFlow<B, C>>
|
||||||
export type InputHandler<B, C> = HandlerFn<B, C> | Handler<B, C>
|
export type InputHandler<B, C> = HandlerFn<B, C> | Handler<B, C>
|
||||||
|
|
||||||
|
@ -35,6 +36,10 @@ export class Handler<B, C> {
|
||||||
this.fn = fn
|
this.fn = fn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
use<Bn, Cn>(f: Mapper<B, C, Bn, Cn>): Handler<Bn, Cn> {
|
||||||
|
return f(this)
|
||||||
|
}
|
||||||
|
|
||||||
then(next: InputHandler<B, C>): Handler<B, C> {
|
then(next: InputHandler<B, C>): Handler<B, C> {
|
||||||
return new Handler(then(this, next))
|
return new Handler(then(this, next))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue