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:
functionis executed first. If it results in an error, theerror_handle_functionis called.- After either the main function or the error handler finishes, the
finallyfunction is executed. This guarantees that thefinallyfunction runs regardless of the success or failure of the main operation.
§Parameters
function: The primary function to execute, which must implement theAsyncRecoverableFunctiontrait.error_handle_function: A function that handles errors, which must implement theAsyncErrorHandlerFunctiontrait.finally: A function that will be executed after the main function and error handler, which must implement theAsyncRecoverableFunctiontrait.
§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
functionfails, theerror_handle_functionis invoked. If this fails as well, it will not stop the execution of thefinallyblock. - 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:
functionis executed first. If it results in an error, theerror_handle_functionis called.- After either the main function or the error handler finishes, the
finallyfunction is executed. This guarantees that thefinallyfunction runs regardless of the success or failure of the main operation.
§Parameters
function: The primary function to execute, which must implement theAsyncRecoverableFunctiontrait.error_handle_function: A function that handles errors, which must implement theAsyncErrorHandlerFunctiontrait.finally: A function that will be executed after the main function and error handler, which must implement theAsyncRecoverableFunctiontrait.
§Returns
- A
AsyncSpawnResult
§Errors
- If the
functionfails, theerror_handle_functionis invoked. If this fails as well, it will not stop the execution of thefinallyblock. - The final block (
finally) is always executed, even if the main function (function) or the error handler (error_handle_function) fails.