chanx

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package chanx 提供无界 channel 等 channel 扩展原语。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Unbounded

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

Unbounded 是一个无界 channel:发送端永不阻塞(值缓存在内部切片中), 接收端从 Out() 读取,保持 FIFO 顺序。适合事件总线、日志队列等 "生产不可阻塞、消费可能滞后" 的场景。

使用:

u := chanx.NewUnbounded[int]()
u.In() <- 1
v := <-u.Out()
u.Close() // 关闭后 Out() 读完剩余值再关闭

func NewUnbounded

func NewUnbounded[T any]() *Unbounded[T]

NewUnbounded 创建并启动一个无界 channel。

func (*Unbounded[T]) Close

func (u *Unbounded[T]) Close()

Close 关闭发送端;缓冲中剩余的值仍可从 Out 读出,读完后 Out 关闭。

func (*Unbounded[T]) In

func (u *Unbounded[T]) In() chan<- T

In 返回发送端(永不阻塞)。Close 后不可再发送。

func (*Unbounded[T]) Out

func (u *Unbounded[T]) Out() <-chan T

Out 返回接收端。In 关闭且缓冲读尽后,Out 也会关闭。

Jump to

Keyboard shortcuts

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