channels

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type UnboundedBacklog

type UnboundedBacklog[V any] struct {
	// contains filtered or unexported fields
}

UnboundedBacklog 是并发安全的无界缓冲区的实现

func NewUnboundedBacklog

func NewUnboundedBacklog[V any]() *UnboundedBacklog[V]

NewUnboundedBacklog 创建一个并发安全的,基于 channel 和缓冲队列实现的无界缓冲区

该缓冲区来源于 gRPC 的实现,用于在不使用额外 goroutine 的情况下实现无界缓冲区

  • 该缓冲区的所有方法都是线程安全的,除了用于同步的互斥锁外,不会阻塞任何东西

func (*UnboundedBacklog[V]) Close

func (ub *UnboundedBacklog[V]) Close()

Close 关闭

func (*UnboundedBacklog[V]) Get

func (ub *UnboundedBacklog[V]) Get() <-chan V

Get 获取可接收消息的读取通道,需要注意的是,每次读取成功都应该通过 Load 函数将缓冲区中的数据加载到读取通道中

func (*UnboundedBacklog[V]) IsClosed

func (ub *UnboundedBacklog[V]) IsClosed() bool

IsClosed 是否已关闭

func (*UnboundedBacklog[V]) Load

func (ub *UnboundedBacklog[V]) Load()

Load 将缓冲区中的数据发送到读取通道中,如果缓冲区中没有数据,则不会发送

  • 在每次 Get 后都应该执行该函数

func (*UnboundedBacklog[V]) Put

func (ub *UnboundedBacklog[V]) Put(t V)

Put 将数据放入缓冲区

type UnboundedRing

type UnboundedRing[T any] struct {
	// contains filtered or unexported fields
}

UnboundedRing 是并发安全的,基于环形缓冲区实现的无界缓冲区

func NewUnboundedRing

func NewUnboundedRing[T any](ctx context.Context) *UnboundedRing[T]

NewUnboundedRing 创建一个并发安全的基于环形缓冲区实现的无界缓冲区

func (*UnboundedRing[T]) Close

func (r *UnboundedRing[T]) Close()

Close 关闭缓冲区

func (*UnboundedRing[T]) Get

func (r *UnboundedRing[T]) Get() <-chan T

Get 获取可接收消息的读取通道

func (*UnboundedRing[T]) IsClosed

func (r *UnboundedRing[T]) IsClosed() bool

IsClosed 是否已关闭

func (*UnboundedRing[T]) Put

func (r *UnboundedRing[T]) Put(v ...T) error

Put 将数据放入缓冲区

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL