Options
All
  • Public
  • Public/Protected
  • All
Menu

Utility handler that allows combining the results of multiple handlers into one. Will run all the handlers and then call the abstract combine function with the results, which should return the output of the class.

If requireAll is true, the handler will fail if any of the handlers do not support the input. If requireAll is false, only the handlers that support the input will be called, only if all handlers reject the input will this handler reject as well. With requireAll set to false, the length of the input array for the combine function is variable (but always at least 1).

Type parameters

Hierarchy

Index

Constructors

Protected constructor

  • new UnionHandler<T>(handlers: T[], requireAll?: boolean): UnionHandler<T>

Properties

Protected Readonly handlers

handlers: T[]

Private Readonly requireAll

requireAll: boolean

Methods

Private allCanHandle

  • allCanHandle(input: InType<T>): Promise<void>
  • Checks if all handlers can handle the input. If not, throw an error based on the errors of the failed handlers.

    Parameters

    • input: InType<T>

    Returns Promise<void>

canHandle

  • canHandle(input: InType<T>): Promise<void>
  • Checks if the input can be handled by this class. If it cannot handle the input, rejects with an error explaining why.

    Parameters

    • input: InType<T>

    Returns Promise<void>

    A promise resolving if the input can be handled, rejecting with an Error if not.

Protected Abstract combine

  • combine(results: ThenArg<ReturnType<T["handle"]>>[]): Promise<ThenArg<ReturnType<T["handle"]>>>
  • Combine the results of the handlers into a single output.

    Parameters

    • results: ThenArg<ReturnType<T["handle"]>>[]

    Returns Promise<ThenArg<ReturnType<T["handle"]>>>

handle

  • handle(input: InType<T>): Promise<ThenArg<ReturnType<T["handle"]>>>

handleSafe

  • handleSafe(input: InType<T>): Promise<ThenArg<ReturnType<T["handle"]>>>