| Crates.io | singletonThread |
| lib.rs | singletonThread |
| version | 2.1.0 |
| created_at | 2024-01-24 13:14:07.115943+00 |
| updated_at | 2025-08-15 13:55:00.272967+00 |
| description | thread in a singleton |
| homepage | |
| repository | https://github.com/hyultis/singletonThread |
| max_upload_size | |
| id | 1112157 |
| size | 36,415 |
SingletonThread is a Rust library designed to manage the execution of a user-defined FnMut function on a
thread following the singleton pattern. This ensures that at any given time, only one instance of the thread
can be active. Before starting a new execution, the previous one must have completed.
This library offers functionality to control and limit thread execution frequency, making it ideal for scenarios where precise timing or controlled thread reuse is needed.
thread_launch(): Attempt to (re)launch the thread while ensuring that only a single thread instance is running.thread_launch_delayabe(): Same as thread_launch() but if the thread is already running, mark the singleton to run one additional time (do not stack).duration_set() or duration_setFPS(): Specify a minimum time interval between successive thread executions (default: 1 ns, can be changed dynamically).loop_set(): Set the thread to continuously run the singleton (loop, can be changed dynamically)[dependencies]
singletonThread = "2.1"
thread-priority crateTo see the library in use, check out the test cases provided: tests.rs.
Below is a brief example showcasing the usage of the library:
fn main()
{
let mut test_thread = SingletonThread::new(move || {
println!("Running my function in a thread!");
});
// Launch the thread.
test_thread.thread_launch();
}
Licensed under either of the following:
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.