0.1.1 • Published 12 months ago

@harnyk/chan v0.1.1

Weekly downloads
-
License
WTFPL
Repository
github
Last release
12 months ago

@harnyk/chan - Go channels for TypeScript

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.

Installation

npm install @harnyk/chan

Usage

See the tests and examples for more information.

Brief reference:

ch := make(chan int)
const ch = new Chan<number>();
ch := make(chan int, 5)
const ch = new Chan<number>(5);
for v := range ch {
    fmt.Println(v)
}
for await (const v of ch) {
    console.log(v);
}
ch <- 42
await ch.send(42);
v, ok := <-ch
const [v, ok] = await ch.recv();
close(ch)
ch.close();
select {
    case ch <- 42:
        fmt.Println("sent")
    case v := <-ch1:
        fmt.Printf("Received %d\n", v)
    default:
        fmt.Println("default")
}
await select()
    .send(ch, 42, () => console.log('sent'))
    .recv(ch1, (v) => console.log(`Received ${v}`))
    .default(() => console.log('default'));

What is supported

  • asynchronous iterating over Chan<T> with for await
  • asynchronous send and recv
  • select-ing over multiple channels

License

WTFPL

Contributors

Mark Harnyk (https://github.com/harnyk)

0.1.1

12 months ago

0.1.0

12 months ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago