CSPLib
Communicating Sequential Processes (CSP) is a way of writing a concurrent application using message passing through channels. It is practically used in Go's channel for communication between threads.
In the textbook CSP as in the figure above, the writer blocks until reader consumes the passing value so as to hold only one value in the channel. However, any reader doesn't exist when writer puts a value in the channel isn't practiacally a case. Also, allowing only one reader limits the use case. So alternatively in this library, writer is never blocked by the reader and allows multiple readers based on the assumption reader is ready when the writer starts putting a value on the channel.
Examples
Example 1
flowchart LR
P1 -->|ping| ch1
ch1 -->|ping| P2
P2 -->|pingpong| ch2
ch2 -->|pingpong| P1
is equivalent to
let = channel;
let = channel;
spawn;
let y = spawn
.await
.unwrap;
assert_eq!
Example 2
flowchart LR
Main -->|1| ch1
ch1 --> P1(x+2)
ch1 --> P2(x*2)
P1 -->|3| ch2
P2 -->|2| ch3
ch2 --> P4(x*y)
ch3 --> P4
P4 --> ch4
ch4 -->|6| Main
is equivalent to
let = channel;
let = channel;
let = channel;
let = channel;
// λx. x+2
spawn;
// λx. x*2
spawn;
// λxy. x*y
spawn;
w1.put.unwrap;
let r4 = ch4.reader;
let ans = r4.get.await.unwrap;
assert_eq!;