Executes an asynchronous action with queuing and provides loading and error state.

  • Type Parameters

    • Data extends unknown = any

      The type of data returned by the action.

    • Payload extends unknown = any

      The type of payload accepted by the action.

    Parameters

    • run: (p: Payload) => Data | Promise<Data>

      The function that represents the action to be executed.

    • Optionaloptions: IParams

      Optional parameters for configuring the behavior of the action execution.

      • onLoadStart

        Callback function to be executed when the action starts loading.

      • onLoadEnd

        Callback function to be executed when the action finishes loading.

      • fallback

        Callback function to be executed when an error occurs and throwError is set to false.

      • throwError

        Specifies whether to throw an error if one occurs during the action execution.

    Returns IResult<Data, Payload>

    • The result object containing the loading state, error state, and the execute function to trigger the action execution.