Expand description
Stoplight is a small library for stoppable threads/tasks.
use stoplight;
use std::sync::atomic::{Ordering};
// spawn our task, this creates a new OS thread.
let th = stoplight::spawn(|stop| {
while !stop.load(Ordering::Relaxed) {}
42
});
// stop() signals the thread to stop, and then join returns its return value.
th.stop();
assert_eq!(th.join().unwrap(), 42);
Structs§
- Thread
- Handle to a stoppable thread.
Functions§
- spawn
- Spawn a new job with cancelation. (re export of stoplight::Thread::spawn)