This package is my humble attempt to provide a Chan<T> class for TypeScript, which would be as much as possible similar to Go's chan T type.
npm install @harnyk/chan
See the tests and examples for more information.
Brief reference:
| Go equivalent | TypeScript | |
|---|---|---|
| Create a channel of `number` with no buffer: |
|
|
| Create a channel of `number` with fixed-size buffer: |
|
|
| Iterate over `Chan` with `for await` |
|
|
| Send a value to `Chan` with `send` |
|
|
| Receive a value from `Chan` with `recv` |
|
|
| Close `Chan` |
|
|
| Select over multiple channels |
|
|
- asynchronous iterating over
Chan<T>withfor await - asynchronous
sendandrecv select-ing over multiple channels
WTFPL
Mark Harnyk (https://github.com/harnyk)