1 unstable release
0.1.1 | Aug 14, 2024 |
---|---|
0.1.0 |
|
#627 in Concurrency
21 downloads per month
12KB
98 lines
chex -- async/sync check exit signal
Chex is a simple rust library which provides a global exit signal which can be easily shared between any/all threads and async tasks in a program.
This allows you to set clear policy in your program of which conditions should teardown the entire program, and make sure that all other independent tasks/threads will receive the exit signal in a somewhat timely fashion and can perform their own teardown logic before exiting. Specifically we can avoid the cases where independent worker threads or tokio runtimes continue running after one of them Panics.
A ChexInstance can be acquired in two ways:
- Cloned from any other ChexInstance
- Acquired from anywhere with an associated function of the global Chex::get_chex_instance()
Usage guidelines:
- Very early in the main task/thread call Chex::init(set_exit_on_panic: bool). After that a ChexInstance can be obtained immediately with .get_instance() and cloned as needed, or acquired at any other point in the program without holding a reference to the original &Chex returned from init, with the associated function Chex::get_chex_instance()
- All threads and tasks which run for a significant amount of time should periodically check whether exit has been signalled, ie as a match within a tokio::select!() block or as a poll-check within non-async forever-loops.
- If panic!() on one thread should be caught to send the exit signal to all other ChexInstance listeners, initialize the library with Chex::init(true). This behavior can also be enabled after the fact with Chex.set_exit_on_panic().
See the examples/ folder for usage with a mix of independent tokio runtimes and non-async worker threads.
dependencies + justification
- async-broadcast: async/sync channels with overflow
- log::error: used on Panic paths only
Dependencies
~555KB