-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
51 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { EventHandler } from "modules/types.ts"; | ||
|
||
/** Options to RelayRunner */ | ||
export type RelayRunnerOptions = { | ||
/** | ||
* If the prev handler is a promise, it will await for it before executing the next handler. | ||
* @default false | ||
*/ | ||
async: boolean; | ||
}; | ||
|
||
/** Handle how to run before and after handler. */ | ||
export class RelayRunner { | ||
/** | ||
* Execute the handler. | ||
* @param prev The result of the previous handler. | ||
* @param next The next handler. | ||
* @param options The options to run the next handler. | ||
*/ | ||
exec<T extends EventHandler>( | ||
prev: any, | ||
next: T, | ||
options?: Partial<RelayRunnerOptions>, | ||
): Promise<ReturnType<T>> | ReturnType<T> { | ||
if (prev instanceof Promise) { | ||
return Promise.resolve(prev).then((res) => next(res)); | ||
} | ||
return next(prev); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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