4个版本 (2个破坏性更新)
使用旧Rust 2015
0.3.1 | 2017年10月11日 |
---|---|
0.3.0 | 2017年6月25日 |
0.2.0 | 2017年6月11日 |
0.1.0 | 2017年6月6日 |
#787 in 并发
用于 snail
12KB
182 行
mrsc

带请求的mpsc。这是一个基于Rust的mpsc的基本构建块,如果你有多个工作者需要在一个共享状态上执行事务,而不必在所有线程之间共享你的状态结构。请注意,事务是阻塞的,因此建议避免在事务处理器中包含昂贵的代码。
安装
将此添加到你的 Cargo.toml
依赖列表
[dependencies]
mrsc = "0.3"
将此添加到你的crate根目录
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