Go-style/CSP-style channels for TypeScript with async/await. Features:
async/await friendly API, for await, AbortSignal
for cancellation
Buffered & unbuffered channels
select() like select{} statement
in Go, for reads & writes
select() can also take any Promise or any async function that takes AbortSignal
Timeout operations with select() + sleep(); abort
via AbortSignal with select() + returnOnAbort()
The return type of select() is inferred for nice exhaustive matching
Operators: merge(),
partitionTime()
Works in Node.js and browsers; relies on global setTimeout, AbortController,
AbortSignal
Zero dependencies
Thoroughly tested
For details see API docs
npm install -E @azerum/ts-csp
Experimental: breaking changes to API are expected
See src/_examples directory:
Ping-pong: common introductory example of channels in Go
Fast producer and slow consumer: demonstrates how backpressure works
Fan-out, fan-in: a common pattern to distribute work among N workers and merge the results back
select():
Batch processing: use of partitionTime():
process channel in groups of N items. Useful e.g. to save data in DB in batches
read() and tryRead()