Function async_recoverable_spawn_catch_finally

Source
pub async fn async_recoverable_spawn_catch_finally<F, E, L>(
    function: F,
    error_handle_function: E,
    finally: L,
) -> Result<(), JoinError>
Expand description

Spawns an asynchronous recoverable function, catches any errors with an error-handling function, and ensures that a final function is always executed, regardless of whether an error occurred.

This function runs a series of operations in an asynchronous context, where:

  • function is executed first. If it results in an error, the error_handle_function is called.
  • After either the main function or the error handler finishes, the finally function is executed. This guarantees that the finally function runs regardless of the success or failure of the main operation.

§Parameters

  • function: The primary function to execute, which must implement the AsyncRecoverableFunction trait.
  • error_handle_function: A function that handles errors, which must implement the AsyncErrorHandlerFunction trait.
  • finally: A function that will be executed after the main function and error handler, which must implement the AsyncRecoverableFunction trait.

§Returns

  • A JoinHandle<()> that can be used to manage the spawned thread, ensuring that all the functions execute in a recoverable context and the final block always runs.

§Errors

  • If the function fails, the error_handle_function is invoked. If this fails as well, it will not stop the execution of the finally block.
  • The final block (finally) is always executed, even if the main function (function) or the error handler (error_handle_function) fails. Spawns an asynchronous recoverable function, catches any errors with an error-handling function, and ensures that a final function is always executed, regardless of whether an error occurred.

This function runs a series of operations in an asynchronous context, where:

  • function is executed first. If it results in an error, the error_handle_function is called.
  • After either the main function or the error handler finishes, the finally function is executed. This guarantees that the finally function runs regardless of the success or failure of the main operation.

§Parameters

  • function: The primary function to execute, which must implement the AsyncRecoverableFunction trait.
  • error_handle_function: A function that handles errors, which must implement the AsyncErrorHandlerFunction trait.
  • finally: A function that will be executed after the main function and error handler, which must implement the AsyncRecoverableFunction trait.

§Returns

  • A AsyncSpawnResult

§Errors

  • If the function fails, the error_handle_function is invoked. If this fails as well, it will not stop the execution of the finally block.
  • The final block (finally) is always executed, even if the main function (function) or the error handler (error_handle_function) fails.