Skip to content
/ js-csp Public

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

Notifications You must be signed in to change notification settings


Repository files navigation

Build Status codecov Dependency Status devDependency Status


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


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");

    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);


There are more under examples directory.


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.


Or, if you use Python's Twisted:

Or, if you use Clojure:


npm install js-csp
bower install js-csp


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.


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


$ 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".



Distributed under MIT License.