js-csp

CSP channels for Javascript (like Clojurescript's core.async, or Go)

  • 所有者: js-csp/js-csp
  • 平台:
  • 許可證:
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

Build Status
codecov
Dependency Status
devDependency Status

js-csp

Communicating sequential processes for Javascript (like Clojurescript core.async, or Go).

Maintainer wanted

This project is at maintenance mode at the moment, and actively looking for new maintainers. Please send us
an issue via github if you are interested.

Current maintainer: hung-phan, gt3

Examples

const csp = require('js-csp');

Pingpong (ported from 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();
});

There are more under examples directory.

Documentation

This is a very close port of Clojurescript's core.async. The most significant difference
is that the IOC logic is encapsulated using generators (yield) instead of macros. Therefore resources on core.async or Go channels are also helpful.

Other

Or, if you use Python's Twisted:
https://github.com/ubolonton/twisted-csp

Or, if you use Clojure:
https://github.com/clojure/core.async

Install

npm install js-csp
bower install js-csp

Contribution

Feel free to open issues for questions/discussions, or create pull requests for improvement.

Some areas that need attention:

  • More documentation, examples, and maybe some visualization. Porting RxJS/Bacon examples may help.
  • Multiplexing, mixing, publishing/subscribing. These need to be tested more. The API could also be improved.
  • Deadlock detection.

Development

These commands are supposed to run separately

$ npm run test:watch
$ npm run lint # for code quality checking
$ npm run flow:watch # to stop server after you are done run npm run flow:stop

Production

$ npm run build

It will transpile all the codes in src to lib, or even better if you use webpack 2 to consume
the lib via "module": "./src/csp.js".

Inspiration

License

Distributed under MIT License.

主要指標

概覽
名稱與所有者js-csp/js-csp
主編程語言JavaScript
編程語言JavaScript (語言數: 1)
平台
許可證
所有者活动
創建於2014-01-29 14:49:13
推送於2022-07-20 03:14:27
最后一次提交2018-02-08 14:50:30
發布數22
最新版本名稱0.9.2 (發布於 )
第一版名稱0.1.0 (發布於 )
用户参与
星數2.3k
關注者數53
派生數121
提交數369
已啟用問題?
問題數79
打開的問題數28
拉請求數49
打開的拉請求數8
關閉的拉請求數11
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?