1 个不稳定版本
0.1.0 | 2020 年 4 月 7 日 |
---|
#379 在 并发
130KB
2K SLoC
Rusty Junctions
Rusty Junctions 是在我本科论文期间开发的 Rust crate。它旨在在 Rust 1.35.0 版本中实现由 Cédric Fournet 和 Georges Gonthier 开发的 Join Calculus 中的 Join 模式。
除了 Join 模式,这个库还引入了 Junction 的概念,它在 Polyphonic C# [2] 中的角色类似。Junctions 作为 Join 模式及其声明通道的总体结构。Junctions 将用于组合 Join 模式的通道分组在一起,并提供 Join Calculus 所展示的关于竞争的本地性属性 [1]。
使用方法
熟悉 Join 模式及其编程范式的开发者应该会发现使用这个 crate 相对简单。使用 Rusty Junctions 可以动态创建 Join 模式,每次过程遵循相同的三个步骤
- 创建一个新的
Junction
。 - 在
Junction
上创建一个或多个新的通道。 - 在
Junction
上声明一个或多个新的 Join 模式。
由于 Join 模式声明的动态性,一旦声明了模式,就可以立即触发。为了触发一个 Join 模式,只需要每个参与 Join 模式声明的通道发送至少一条消息。一旦 Junction 发现已经收到了触发特定 Join 模式所需的所有消息,它将自动执行。
以下是一个展示该库基本使用的非常简短的示例
// The only struct that needs to be brought into score is the Junction itself.
use rusty_junctions::Junction;
fn main() {
// Create a new Junction.
let j = Junction::new();
// Create new channels on the Junction j.
let name = j.send_channel::<String>();
let value = j.send_channel::<i32>();
// Declare a new Join Pattern on the Junction using the channels above.
j.when(&name).and(&value).then_do(|n, v| { println!("{} {}", n, v); });
// Send all the required messages for the Join Pattern above to fire.
value.send(1729).unwrap();
name.send(String::from("Taxi")).unwrap();
}
更多示例,包括更复杂的示例,可以在本存储库的 examples
文件夹中找到。
特别感谢
我要感谢我的论文导师 Ian Stark 博士,他最初提出了导致这个库的论文主题。没有他,他的持续支持和无价的宝贵意见来解决关键挑战,这一切都不可能实现。
参考文献
[1] https://www.microsoft.com/en-us/research/wp-content/uploads/2017/01/join-tutorial.pdf
[2] https://dl.acm.org/doi/abs/10.1145/1018203.1018205