1.0.1 • Published 7 years ago

js-csp v1.0.1

Weekly downloads
2,073
License
MIT
Repository
github
Last release
7 years ago

Build Status codecov Dependency Status devDependency Status

js-csp

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

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.

1.0.1

7 years ago

1.0.0

7 years ago

0.9.3

7 years ago

0.9.2

7 years ago

0.9.1

7 years ago

0.9.0

7 years ago

0.8.1

7 years ago

0.8.0

8 years ago

0.7.5

8 years ago

0.7.4

8 years ago

0.7.3

8 years ago

0.7.2

8 years ago

0.7.1

8 years ago

0.7.0

8 years ago

0.6.5

8 years ago

0.6.4

8 years ago

0.6.3

8 years ago

0.6.2

8 years ago

0.6.1

8 years ago

0.6.0

8 years ago

0.5.0

9 years ago

0.4.2

9 years ago

0.4.1

9 years ago

0.4.0

9 years ago

0.3.4

9 years ago

0.3.3

9 years ago

0.3.2

9 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.2-dev

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago