Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AsyncHandler<TIn, TOut>

Simple interface for classes that can potentially handle a specific kind of data asynchronously.

Type parameters

  • TIn = void

  • TOut = void

Hierarchy

  • AsyncHandler

Index

Constructors

Methods

Constructors

constructor

  • Type parameters

    • TIn = void

    • TOut = void

    Returns AsyncHandler<TIn, TOut>

Methods

canHandle

  • canHandle(input: TIn): Promise<void>
  • Checks if the input data can be handled by this class. Throws an error if it can't handle the data.

    Parameters

    • input: TIn

      Input data that would be handled potentially.

    Returns Promise<void>

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

Abstract handle

  • handle(input: TIn): Promise<TOut>
  • Handles the given input. This should only be done if the canHandle function returned true.

    Parameters

    • input: TIn

      Input data that needs to be handled.

    Returns Promise<TOut>

    A promise resolving when the handling is finished. Return value depends on the given type.

handleSafe

  • handleSafe(data: TIn): Promise<TOut>
  • Helper function that first runs the canHandle function followed by the handle function. Throws the error of the canHandle function if the data can't be handled, or returns the result of the handle function otherwise.

    Parameters

    • data: TIn

      The data to handle.

    Returns Promise<TOut>

    The result of the handle function of the handler.