#language #time #hyperlane #day #format

recoverable-thread-pool

A thread pool that supports automatic recovery from panics, allowing threads to restart after a panic. Useful for resilient and fault-tolerant concurrency in network and web programming.

26 stable releases

Uses new Rust 2024

2.3.1 Apr 18, 2025
2.1.4 Mar 30, 2025
1.1.2 Jan 15, 2025
0.3.0 Jan 11, 2025

#2150 in Network programming

Download history 960/week @ 2025-01-14 229/week @ 2025-01-21 12/week @ 2025-01-28 237/week @ 2025-02-04 243/week @ 2025-02-11 143/week @ 2025-02-18 473/week @ 2025-02-25 187/week @ 2025-03-04 500/week @ 2025-03-11 417/week @ 2025-03-18 390/week @ 2025-03-25 559/week @ 2025-04-01 315/week @ 2025-04-08 359/week @ 2025-04-15 175/week @ 2025-04-22 63/week @ 2025-04-29

971 downloads per month
Used in 5 crates (3 directly)

MIT license

15KB
279 lines

recoverable-thread-pool

Official Documentation

Api Docs

A thread pool that supports automatic recovery from panics, allowing threads to restart after a panic. Useful for resilient and fault-tolerant concurrency in network and web programming.

Installation

To use this crate, you can run cmd:

cargo add recoverable-thread-pool

Use

Sync

use recoverable_thread_pool::*;
use std::{thread::sleep, time::Duration};
let thread_pool: ThreadPool = ThreadPool::new(1);
let first_res: SendResult = thread_pool.execute(|| {
    println!("first");
});
println!("{:?}", first_res);
let panic_res: SendResult = thread_pool.execute_with_catch(
    || {
        panic!("[panic]");
    },
    |err| {
        println!("Catch panic {}", err);
    },
);
println!("{:?}", panic_res);
let second_res: SendResult = thread_pool.execute_with_catch_finally(
    || {
        panic!("[panic]");
    },
    |_err| {
        panic!("[panic]");
    },
    || {
        println!("finally");
    },
);
println!("{:?}", second_res);
sleep(Duration::from_secs(10));

Async

use recoverable_thread_pool::*;
use std::{thread::sleep, time::Duration};
let thread_pool: ThreadPool = ThreadPool::new(1);
let first_res: SendResult = thread_pool.async_execute(|| async {
    println!("first");
});
println!("{:?}", first_res);
let panic_res: SendResult = thread_pool.async_execute_with_catch(
    || async {
        panic!("[panic]");
    },
    |err| async move {
        println!("Catch panic {}", err);
    },
);
println!("{:?}", panic_res);
let second_res: SendResult = thread_pool.async_execute_with_catch_finally(
    || async {
        panic!("[panic]");
    },
    |_err| async {
        panic!("[panic]");
    },
    || async {
        println!("finally");
    },
);
println!("{:?}", second_res);
sleep(Duration::from_secs(10));

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Contact

For any inquiries, please reach out to the author at ltpp-universe root@ltpp.vip.

Dependencies

~4–9.5MB
~84K SLoC