https://github.com/smallnest/chanx
unbounded chan
https://github.com/smallnest/chanx
Last synced: 2 months ago
JSON representation
unbounded chan
- Host: GitHub
- URL: https://github.com/smallnest/chanx
- Owner: smallnest
- License: mit
- Created: 2021-05-10T09:35:20.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-05-21T15:35:36.000Z (about 1 year ago)
- Last Synced: 2025-04-14T16:56:20.630Z (3 months ago)
- Language: Go
- Size: 14.6 KB
- Stars: 441
- Watchers: 9
- Forks: 61
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# chanx
Unbounded chan with ringbuffer.
[](https://opensource.org/licenses/MIT)   [](https://goreportcard.com/report/github.com/smallnest/chanx) [](http://godoc.org/github.com/smallnest/chanx)
Refer to the below articles and issues:
1. https://github.com/golang/go/issues/20352
2. https://stackoverflow.com/questions/41906146/why-go-channels-limit-the-buffer-size
3. https://medium.com/capital-one-tech/building-an-unbounded-channel-in-go-789e175cd2cd
4. https://erikwinter.nl/articles/2020/channel-with-infinite-buffer-in-golang/## Usage
If you want to use it with Go 1.17.x or below, you can use `github.com/smallnest/[email protected]`.
Since `github.com/smallnest/[email protected]`, it support Go generics.```go
ch := NewUnboundedChan(1000)
// or ch := NewUnboundedChanSize(10,200,1000)go func() {
for ...... {
...
ch.In <- ... // send values
...
}close(ch.In) // close In channel
}()for v := range ch.Out { // read values
fmt.Println(v)
}```