[][src]Crate drop_worker

Provides helpful worker threads that get joined when dropped.

Features

The crossbeam feature will use unbounded crossbeam channels instead of std channels.

Example

#[macro_use]
extern crate drop_worker;

use drop_worker::{recv_data, try_err, DropWorker, Receiver};

fn main() {
    let _worker = DropWorker::new(work);

    let mut receiver = DropWorker::new(rec);
    receiver.send(5);
}

fn work(recv: Receiver<()>) {
    // setup
    loop {
        try_err!(recv);
        // do work
    }
}

fn rec(recv: Receiver<usize>) {
    loop {
        let data = recv_data!(recv);
        assert_eq!(data, 5);
    }
}

Macros

recv_data

Waits for data from the DropWorker and returns the data. If the DropWorker gets dropped then this will call return.

try_err

Checks if the DropWorker was dropped and if so then this will call return.

Structs

DropWorker

Provides a worker thread that can receive structs of type T. When this instance is dropped, it will signal the worker thread to stop and wait until joined.

Receiver

The receiving half of Rust's channel (or sync_channel) type. This half can only be owned by one thread.

Enums

TryRecvError

This enumeration is the list of the possible reasons that try_recv could not return data when called. This can occur with both a channel and a sync_channel.