Expand description
This crate provides an abstraction for outsourcing a piece of work to another thread. This is a common
pattern in not only async programs, but OS-specific programs where it is expected that a certain piece of
work is done on a certain thread. To accomplish this, the crate provides a Two, short for “Two Way
Oneshot” (not a recursive acronym). It is implemented as a sender and a receiver, similar to other channels
in the Rust ecosystem. The primary difference is that the sender comes bundled with a data type of your
choice, and that the sender and receiver are both consumed upon data transmission.
§Example
Creates a thread that processes the work of squaring a number.
use orphan_crippler::two;
use std::thread;
let (mut sender, receiver) = two::<i32, i32>(5);
thread::spawn(move || {
let input = sender.input().unwrap();
let result = input * input;
sender.send::<i32>(result);
});
assert_eq!(receiver.recv(), 25);§Features
If the parking_lot feature is enabled, this crate uses mutexes from the parking_lot crate internally,
rather than std::sync mutexes. This is recommended if you are using parking_lot mutexes elsewhere in your
application.
Structs§
- Receiver
Deprecated - The receiver for the two-way oneshot channel. It is consumed upon receiving its data.
- Sender
Deprecated - The sender for the two-way oneshot channel. It is consumed upon sending its data.
Functions§
- complete
Deprecated - Creates a receiver that automatically resolves.
- complete_
boxed Deprecated - Equivalent to
complete, but uses a boxedRto avoid a layer of indirection, if you already have one of those. - two
Deprecated - Creates a sender and a receiver for the two-way oneshot (
two) channel.