Function async_recoverable_spawn

Source
pub async fn async_recoverable_spawn<F>(function: F) -> Result<(), JoinError>
Expand description

Spawns a new thread to run the provided function function in a recoverable manner. If the function function panics during execution, the panic will be caught, and the thread will terminate without crashing the entire program.

§Parameters

  • function: A function of type function to be executed in the spawned thread. It must implement FnOnce(), Send, Sync, and 'static traits.
    • FnOnce(): The function is callable with no arguments and no return value.
    • Send: The function can be safely transferred across thread boundaries.
    • Sync: The function can be shared across threads safely.
    • 'static: The function does not contain references to non-static data (i.e., data that lives beyond the function’s scope).

§Returns

  • A AsyncSpawnResult

§Panics

  • This function itself will not panic, but the function function could panic during execution. The panic will be caught, preventing the program from crashing.