Expand description
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 theDropWorker
gets dropped then this will callreturn
. - try_err
- Checks if the
DropWorker
was dropped and if so then this will callreturn
.
Structs§
- Drop
Worker - 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
(orsync_channel
) type. This half can only be owned by one thread.
Enums§
- TryRecv
Error - This enumeration is the list of the possible reasons that
try_recv
could not return data when called. This can occur with both achannel
and async_channel
.