用于 JavaScript 的 CSP 通道(如 Clojurescript 的 core.async 或 Go)
为 JavaScript 通信顺序过程(如 Clojurescript core.async 或 Go)。
目前这个项目处于维护模式,并正在积极寻找新的维护者。请将您的申请发送给我们 如果您感兴趣,可以通过 GitHub 发布问题。 当前维护人员: hung-phan, gt3
const csp = require('js-csp');Pingpong(从 Go 中移植而来)。
function* player(name, table) {
while (true) {
let ball = yield csp.take(table);
if (ball === csp.CLOSED) {
console.log(name + ": table's gone");
return;
}
ball.hits += 1;
console.log(`${name} ${ball.hits}`);
yield csp.timeout(100);
yield csp.put(table, ball);
}
}
csp.go(function* () {
const table = csp.chan();
csp.go(player, ["ping", table]);
csp.go(player, ["pong", table]);
yield csp.put(table, {hits: 0});
yield csp.timeout(1000);
table.close();
});在 examples 目录下还有更多示例。
这是一个非常接近 Clojurescript 的 core.async 的端口。最显著的区别是,IOC 逻辑是通过生成器(yield)而不是宏来封装的。因此,使用 core.async 或 Go 通道上的资源也很有帮助。
需要注意的一些方面: - 更多的文档、示例和可能的可视化。移植 RxJS/Bacon 示例可能会有所帮助。 - 多路复用、混合、发布/订阅。这些需要进行更多的测试。API 也可以得到改进。 - 死锁检测。
暂无开放 Issues,或尚未同步最近议题。