fix: Comments on async handler functions parameters

This commit is contained in:
Matthieu Bosquet 2021-01-11 23:35:34 +00:00 committed by Joachim Van Herwegen
parent ba42861699
commit 107fbad0e0

View File

@ -5,9 +5,9 @@ export abstract class AsyncHandler<TIn = void, TOut = void> {
/** /**
* Checks if the input data can be handled by this class. * Checks if the input data can be handled by this class.
* Throws an error if it can't handle the data. * Throws an error if it can't handle the data.
* @param input - Input data that would be handled potentially. * @param input - Input data that could potentially be handled.
* *
* @returns A promise resolving if this input can be handled, rejecting with an Error if not. * @returns A promise resolving if the input can be handled, rejecting with an Error if not.
*/ */
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
public async canHandle(input: TIn): Promise<void> { public async canHandle(input: TIn): Promise<void> {
@ -16,6 +16,7 @@ export abstract class AsyncHandler<TIn = void, TOut = void> {
/** /**
* Handles the given input. This should only be done if the {@link canHandle} function returned `true`. * Handles the given input. This should only be done if the {@link canHandle} function returned `true`.
* Therefore, consider using the {@link handleSafe} function instead.
* @param input - Input data that needs to be handled. * @param input - Input data that needs to be handled.
* *
* @returns A promise resolving when the handling is finished. Return value depends on the given type. * @returns A promise resolving when the handling is finished. Return value depends on the given type.
@ -26,9 +27,10 @@ export abstract class AsyncHandler<TIn = void, TOut = void> {
* Helper function that first runs the canHandle function followed by the handle function. * Helper function that first runs the canHandle function followed by the handle function.
* Throws the error of the {@link canHandle} function if the data can't be handled, * Throws the error of the {@link canHandle} function if the data can't be handled,
* or returns the result of the {@link handle} function otherwise. * or returns the result of the {@link handle} function otherwise.
* @param data - The data to handle. * @param input - Input data that will be handled if it can be handled.
* *
* @returns The result of the handle function of the handler. * @returns A promise resolving if the input can be handled, rejecting with an Error if not.
* Return value depends on the given type.
*/ */
public async handleSafe(input: TIn): Promise<TOut> { public async handleSafe(input: TIn): Promise<TOut> {
await this.canHandle(input); await this.canHandle(input);