Executes an asynchronous action with options for handling loading, error, and cancellation.

  • Type Parameters

    • Data extends unknown = any

      The data type returned by the action.

    • Payload extends unknown = any

      The payload type passed to the action.

    Parameters

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

      The action function to execute.

    • Optionaloptions: IParams

      Optional parameters for customizing behavior.

      • onLoadStart

        A callback function to run when the action starts loading.

      • onLoadEnd

        A callback function to run when the action finishes loading.

      • fallback

        A callback function to handle errors when throwError is set to false.

      • throwError

        Whether to throw an error when the action fails.

    Returns IResult<Data, Payload>

    • An object containing loading, error, and execute properties.