Unbounded chan with ringbuffer.
Refer to the below articles and issues:
If you want to use it with Go 1.17.x or below, you can use github.com/smallnest/chanx@1.0.0
.
Since github.com/smallnest/chanx@1.1.0
, it support Go generics.
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)
}