function one() {
console.log("one");
setTimeout(one, 1000);
}
function two() {
console.log("two");
setTimeout(two, 2000);
}
one();
two();
They are executing concurrently, but never in parallel (since javascript is single threaded).Now, how do you coordinate them if you need to? This is what CSP helps you do.
Maybe you could present the CSP alternative, and a basic example use case?
* edit: I guess a basic example is a sliding-buffer that only keeps, and thus only reacts to, the last mouse event. Is this on the right track?
In vanilla javascript, you have to resort to breaking your code up into callbacks, which looks trivial in a two function example but becomes unwieldy once you add a few layers and do error handling.
With CSP you organize your code around channels according to the code's logic, rather than according to the needs of coordination. This makes things like error handling and reasoning about your logic much simpler.
Concurrency does not necessarily mean parallelism (multi-threading). CSP-derived mechanisms provide abstractions for units-of-work to yield control to other units-of-work. Here, a unit of work is a function invocation, but it can be a block, a thread-like object etc. With such primitives it is fairly easy to build cooperative (as opposed to pre-emptive) concurrency mechanisms.
For a mature example, see e.g. http://www.stackless.com/