Function spawn

Source
pub fn spawn<T, F>(f: F) -> Thread<T>
where F: FnOnce(Arc<AtomicBool>) -> T + Send + 'static, T: Send + 'static,
Expand description

Spawn a new job with cancelation. (re export of stoplight::Thread::spawn)

Examples found in repository?
examples/simple.rs (lines 6-9)
4fn main() {
5    // spawn our task, this creates a new OS thread.
6    let th = stoplight::spawn(|stop| {
7        while !stop.load(Ordering::Relaxed) {}
8        42
9    });
10
11    // stop() signals the thread to stop, and then join returns its return value.
12    th.stop();
13    assert_eq!(th.join().unwrap(), 42);
14}