https://github.com/bakerface/csp
Communicating Sequential Processes in TypeScript
https://github.com/bakerface/csp
Last synced: 8 months ago
JSON representation
Communicating Sequential Processes in TypeScript
- Host: GitHub
- URL: https://github.com/bakerface/csp
- Owner: bakerface
- Created: 2020-04-25T15:38:51.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T04:40:10.000Z (over 3 years ago)
- Last Synced: 2025-06-18T03:09:53.255Z (11 months ago)
- Language: TypeScript
- Size: 553 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CSP
**Communicating Sequential Processes in TypeScript**
## Example
``` typescript
import * as csp from "@bakerface/csp";
const sleep = (ms: number) =>
new Promise((resolve) => setTimeout(resolve, ms));
async function producer(
ch: csp.OutputChannel,
id: string,
idle: number
) {
for (;;) {
await sleep(idle);
await csp.put(ch, id);
}
}
async function consumer(ch: csp.InputChannel) {
for (;;) {
const id = await csp.take(ch);
console.log(id);
}
}
async function main() {
const ch = csp.chan();
await Promise.all([
producer(ch, "250ms", 250),
producer(ch, "1s", 1000),
consumer(ch),
]);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
```