A simple multithreading implementation. Examples:
```rust use std::{ thread::sleep, time::Duration }; use threadder::ThreadPool;
fn main() { // Warning: Threadpools MUST be declared as mutable! // If the threadpool is not mutable, it won't be able to switch threads. // Create a 4-thread threadpool let mut mythreadpool = ThreadPool::new(4); for _ in 0..4 { // Clojures can (optionally) be boxed. mythreadpool.send( || { println!("Goodnight, world!"); sleep(Duration::fromsecs(3)); println!("Goodmorning, world!"); } ); } // MUST be ran at the end of the program. Ensures all threads exit PROPERLY. Without this, // all threads will shut down as soon as the 'main' thread shuts down -- which isn't desirable // when your thread finishes 3 seconds AFTER main does. mythreadpool.stop(); // This drops the transmitter which breaks the listener // loop and joins the thread, allowing it to exit properly without landing the program in an endless loop } ```