[][src]Struct stoplight::Thread

pub struct Thread<T> { /* fields omitted */ }

Handle to a stoppable thread.

Methods

impl<T> Thread<T> where
    T: Send + 'static, 
[src]

pub fn spawn<F>(f: F) -> Thread<T> where
    F: FnOnce(Arc<AtomicBool>) -> T + Send + 'static, 
[src]

Spawn a new job with cancelation.

pub fn join(self) -> Result<T, Box<dyn Any + Send + 'static>>[src]

Join waits for the thread to exit then returns the return value.

pub fn stop(&self)[src]

Signal the Thread to stop, To wait for the thread to exit call join.

pub fn thread(&self) -> &Thread[src]

Extracts a handle to the underlying thread.

use stoplight;
use std::sync::atomic::{Ordering};

let th = stoplight::spawn(|stop| {
    while !stop.load(Ordering::Relaxed) {}
    42
});

let thread = th.thread();
eprintln!("thread id: {:?}", thread.id());

Auto Trait Implementations

impl<T> Send for Thread<T>

impl<T> Sync for Thread<T>

impl<T> Unpin for Thread<T>

impl<T> !UnwindSafe for Thread<T>

impl<T> !RefUnwindSafe for Thread<T>

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]