Options
All
  • Public
  • Public/Protected
  • All
Menu

Class WaterfallHandler<TIn, TOut>

A composite handler that tries multiple handlers one by one until it finds a handler that supports the input. The handlers will be checked in the order they appear in the input array, allowing for more fine-grained handlers to check before catch-all handlers.

Type parameters

  • TIn

  • TOut

Hierarchy

  • WaterfallHandler

Implements

Index

Constructors

constructor

Properties

Private Readonly handlers

handlers: AsyncHandler<TIn, TOut>[]

Protected Readonly logger

logger: Logger = getLoggerFor(this)

Methods

canHandle

  • canHandle(input: TIn): Promise<void>
  • Checks if any of the stored handlers can handle the given input.

    Parameters

    • input: TIn

      The data that would need to be handled.

    Returns Promise<void>

    A promise resolving if at least 1 handler supports to input, or rejecting if none do.

Private findHandler

  • Finds a handler that can handle the given input data. Otherwise an error gets thrown.

    Parameters

    • input: TIn

      The input data.

    Returns Promise<AsyncHandler<TIn, TOut>>

    A promise resolving to a handler that supports the data or otherwise rejecting.

handle

  • handle(input: TIn): Promise<TOut>
  • Finds a handler that supports the given input and then lets it handle the given data.

    Parameters

    • input: TIn

      The data that needs to be handled.

    Returns Promise<TOut>

    A promise corresponding to the handle call of a handler that supports the input. It rejects if no handlers support the given data.

handleSafe

  • handleSafe(input: TIn): Promise<TOut>
  • Identical to AsyncHandler.handleSafe but optimized for composite by only needing 1 canHandle call on members.

    Parameters

    • input: TIn

      The input data.

    Returns Promise<TOut>

    A promise corresponding to the handle call of a handler that supports the input. It rejects if no handlers support the given data.