type Awaited = T extends PromiseLike ? U : T; export type AsyncHandlerInput> = Parameters[0]; export type AsyncHandlerOutput> = Awaited>; /** * Simple interface for classes that can potentially handle a specific kind of data asynchronously. * Actually a class and not an interface to have a base implementation of `canHandle` and `handleSafe`, * but can also be used as an interface. */ export declare abstract class AsyncHandler { /** * Checks whether the input can be handled by this class. * If it cannot handle the input, rejects with an error explaining why. * * @param input - Input that could potentially be handled. * * @returns A promise resolving if the input can be handled, rejecting with an Error if not. */ canHandle(input: TIn): Promise; /** * Handles the given input. This may only be called if {@link canHandle} did not reject. * When unconditionally calling both in sequence, consider {@link handleSafe} instead. * * @param input - Input that needs to be handled. * * @returns A promise resolving when handling is finished. */ abstract handle(input: TIn): Promise; /** * Helper function that first runs {@link canHandle} followed by {@link handle}. * Throws the error of {@link canHandle} if the data cannot be handled, * or returns the result of {@link handle} otherwise. * * @param input - Input data that will be handled if it can be handled. * * @returns A promise resolving if the input can be handled, rejecting with an Error if not. */ handleSafe(input: TIn): Promise; } export {};