Documentation ¶
Index ¶
- Variables
- type Ring
- func (b *Ring[T]) Cap() int
- func (b *Ring[T]) IsEmpty() bool
- func (b *Ring[T]) Len() int
- func (b *Ring[T]) Peek() (t T, err error)
- func (b *Ring[T]) Read() (T, error)
- func (b *Ring[T]) ReadAll() []T
- func (b *Ring[T]) ReadMulti(n int) ([]T, error)
- func (b *Ring[T]) Reset()
- func (b *Ring[T]) Write(v T)
- type RingUnbounded
- type Unbounded
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrBufferIsEmpty = errors.New("buffer is empty") // 缓冲区为空
)
Functions ¶
This section is empty.
Types ¶
type Ring ¶
type Ring[T any] struct { // contains filtered or unexported fields }
Ring 环形缓冲区
type RingUnbounded ¶
type RingUnbounded[T any] struct { // contains filtered or unexported fields }
RingUnbounded 基于环形缓冲区实现的无界缓冲区
func NewRingUnbounded ¶
func NewRingUnbounded[T any](bufferSize int) *RingUnbounded[T]
NewRingUnbounded 创建一个并发安全的基于环形缓冲区实现的无界缓冲区
func (*RingUnbounded[T]) Close ¶
func (b *RingUnbounded[T]) Close() <-chan struct{}
Close 关闭缓冲区,关闭后将不再接收新数据,但是已有数据仍然可以读取
type Unbounded ¶
type Unbounded[V any] struct { // contains filtered or unexported fields }
Unbounded 是无界缓冲区的实现
func NewUnbounded ¶
NewUnbounded 创建一个无界缓冲区
- generateNil: 生成空值的函数,该函数仅需始终返回 nil 即可
该缓冲区来源于 gRPC 的实现,用于在不使用额外 goroutine 的情况下实现无界缓冲区
- 该缓冲区的所有方法都是线程安全的,除了用于同步的互斥锁外,不会阻塞任何东西
Click to show internal directories.
Click to hide internal directories.