Communicating Sequential Process in All of JavaScript
A zero-dependency ES module that implements CSP style concurrency in Browser, Node and Deno.
The implementation is mapped to Go's channel semantics as close as possible unless the nature of JS advices otherwise.
import * as csp from "https://raw.githubusercontent.com/BlowaterNostr/csp/master/csp.ts";
Please refer to tests.
My motivation of writing it is not merely an intellectual pursue of reinventing the wheel, considering there are already at least 3 implementations of CSP in JavaScript.
I need a robust concurreny model that works great both in a single process and across the network. I also want to use the "new" async iterable iterator added to JavaScript since es2018 and use TypeScript for delightful library authoring & consumption.
None of the previous CSP implementations in JS meets my requirement so that I have to implement my own. It's faster, safer, more robust in both my development happiness and runtime efficiency.
After much research, I have chosen CSP over Actor Model because
- CSP can be used for coordination.
- CSP works better in a single-process situation.
- Go & Clojure has native & robust CSP so that I can have a reference.
Reactive programming itself is good. But RxJS
is a terrible implementation. Its API is bloated. It is terribly slow. It's hard
to learn and use.
With 300 lines of code, csp.ts
achieves the same goal as RxJS
but smaller, faster, simpler.
CSP makes reactive programming great again.