Expand description
Uni- and bidirectional channels between processes.
§Channels
Create and use a unidirectional channel:
let (mut sender, mut receiver): (Sender<i32>, Receiver<i32>) = channel::<i32>()?;
sender.send(&57)?;
drop(sender);
assert_eq!(receiver.recv()?, Some(57));
assert_eq!(receiver.recv()?, None);
Create and use a bidirectional channel:
let (mut side1, mut side2) = duplex::<i32, (i32, i32)>()?;
side1.send(&57)?;
assert_eq!(side2.recv()?, Some(57));
side2.send(&(1, 2))?;
assert_eq!(side1.recv()?, Some((1, 2)));
drop(side1);
assert_eq!(side2.recv()?, None);
§Processes
To start a child process, you use the spawn
method generated by #[func]
:
ⓘ
#[func]
fn my_process() {
...
}
let child = my_process.spawn()?;
You can then kill the child, get its PID, or join it (i.e. wait till it returns and obtain the returned value).
Structs§
- Synchronous implementation marker type.
- The subprocess object created by calling
spawn
on a function annottated with#[func]
. - A side of a bidirectional channel.
- The receiving side of a unidirectional channel.
- The transmitting side of a unidirectional channel.
Functions§
- Create a unidirectional channel.
- Create a bidirectional channel.