Skip to content

azerum/ts-csp

Repository files navigation

NPM version

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

Install

npm install -E @azerum/ts-csp

Stability

Experimental: breaking changes to API are expected

Examples

See src/_examples directory:

Inspired by

  • Go channels
  • Communicating Sequential Processes - CSP
  • @thi.ng/csp - design of return values of read() and tryRead()

About

Go-style/CSP-style channels for TypeScript with async/await, AbortSignal cancellation, select()

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors