Crates.io | mrsc |
lib.rs | mrsc |
version | 0.3.1 |
source | src |
created_at | 2017-06-06 06:29:16.36948 |
updated_at | 2017-10-11 16:32:13.880214 |
description | mpsc with requests |
homepage | |
repository | https://github.com/kpcyrd/mrsc |
max_upload_size | |
id | 17915 |
size | 12,680 |
mpsc with requests. This is a basic building block based on rusts mpsc if you have multiple workers that need to execute transactions on a shared state, without having to share your state struct across all threads. Beware that transactions are blocking, so it's recommended to avoid expensive code in the transaction handler.
Add this to your Cargo.toml
dependency list:
[dependencies]
mrsc = "0.3"
Add this to your crate root:
extern crate msrc
use mrsc;
use std::thread;
let server: mrsc::Server<u32, String> = mrsc::Server::new();
let channel = server.pop();
thread::spawn(move || {
let req = server.recv().unwrap();
let reply = {
let msg = req.get();
println!("request: {:?}", msg);
"hello world".to_string()
};
req.reply(reply).unwrap();
});
let response = channel.req(123).unwrap();
let reply = response.recv().unwrap();
println!("response: {:?}", reply);
MIT