Crates.io | ipc_channel_adapter |
lib.rs | ipc_channel_adapter |
version | 0.1.2 |
source | src |
created_at | 2024-05-11 08:28:47.80786 |
updated_at | 2024-05-12 08:47:40.146145 |
description | Provides a utility for fast cross process communication |
homepage | |
repository | |
max_upload_size | |
id | 1236736 |
size | 29,072 |
This utility wraps ipc-channel to handle the handshake and offers with standard channels.
This utility also offers a request/response wrapper for messages
It supports Tokio for non-blocking operation
fn main() {
// Send requests to child
// Request to send to child is u32
// Response coming back from child u64
let child_sender = ChildSender::<u32, u64>::new().unwrap();
// Receive requests from child
// Request coming from child is u32
// Response to send back to child is u64
let (child_receiver, child_rx) = ChildReceiver::<u32, u64>::new().unwrap();
// Spawn child process and give it the names of the IPC channels
let child_process = spawn_child_process("your_child_process")
.env("IPC_RECEIVER_NAME", child_receiver.server_name)
.env("IPC_SENDER_NAME", child_sender.server_name)
.spawn();
thread::spawn(move || {
while let Ok((v, reply)) = child_rx.recv() {
println!("[Host] Received: {}", v);
reply.send(v).unwrap()
}
});
let response = child_sender.send_blocking(42);
println!("[Host] Response: {}", response);
}
fn main() {
// Get name of IPC servers
let host_receiver_server = env::var("IPC_RECEIVER_NAME").unwrap();
let host_sender_server = env::var("IPC_SENDER_NAME").unwrap();
// Send requests to host
// Request to send to host is u32
// Response coming back from host u64
let host_sender = HostSender::<u32, u64>::new(&host_receiver_server).unwrap();
// Receive requests from host
// Request coming from host is u32
// Response to send back to host is u64
let (_host_receiver, host_receiver_rx) = HostReceiver::<u32, u64>::new(&host_sender_server).unwrap();
thread::spawn(move || {
while let Ok((v, reply)) = host_receiver_rx.recv() {
println!("[Child] Received: {}", v);
reply.send(v).unwrap()
}
});
let response = host_sender.send_blocking(43);
println!("[Child] Response: {}", response);
}