https://github.com/golang-design/chann
a unified channel package for buffered, unbuffered, and unbounded channels
https://github.com/golang-design/chann
channels generics golang unbounded-channel
Last synced: 6 months ago
JSON representation
a unified channel package for buffered, unbuffered, and unbounded channels
- Host: GitHub
- URL: https://github.com/golang-design/chann
- Owner: golang-design
- License: mit
- Created: 2021-09-10T18:18:48.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-01-10T02:10:54.000Z (over 2 years ago)
- Last Synced: 2025-04-01T07:21:21.881Z (6 months ago)
- Topics: channels, generics, golang, unbounded-channel
- Language: Go
- Homepage: https://golang.design/x/chann
- Size: 38.1 KB
- Stars: 39
- Watchers: 3
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# chann  
a unified channel package in Go
```go
import "golang.design/x/chann"
```This package requires Go 1.18.
## Basic Usage
Different types of channels:
```go
ch := chann.New[int]() // unbounded, capacity unlimited
ch := chann.New[func()](chann.Cap(0)) // unbufferd, capacity 0
ch := chann.New[string](chann.Cap(100)) // buffered, capacity 100
```Send and receive operations:
```go
ch.In() <- 42
println(<-ch.Out()) // 42
```Close operation:
```go
ch.Close()
```Channel properties:
```go
ch.Len() // the length of the channel
ch.Cap() // the capacity of the channel
```See https://golang.design/research/ultimate-channel for more details of
the motivation of this abstraction.## License
MIT | © 2021 The [golang.design](https://golang.design) Initiative Authors, written by [Changkun Ou](https://changkun.de).