Help us shape the future of Go! Take the 2026 Go Developer Survey

progress

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package progress 泛型事件总线。 多订阅者广播,每个订阅者 64 缓冲,满了就丢(观测数据允许有损)。 发布永不阻塞(订阅者慢不拖慢主链路)。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

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

Bus 泛型多订阅者广播总线。

func NewBus

func NewBus[T any]() *Bus[T]

NewBus 创建事件总线。

func (*Bus[T]) Dropped

func (b *Bus[T]) Dropped() int64

Dropped 累计丢弃的事件数(订阅者积压时)。有损是声明的设计, 计数让"进度条停在中间态"可归因。

func (*Bus[T]) Publish

func (b *Bus[T]) Publish(e T)

Publish 非阻塞广播。nil Bus 安全(no-op)。

func (*Bus[T]) Subscribe

func (b *Bus[T]) Subscribe(ctx context.Context) (<-chan T, func())

Subscribe 注册订阅者;返回取消函数(ctx 结束也会自动取消)。 nil Bus 安全:返回永不产出的 nil channel 与 no-op cancel(与 Publish/Dropped 同一 nil 契约)。 cancel 与 ctx 结束双向收口:任一发生,监听 goroutine 都会退出—— 此前手动 cancel 只删 channel 不唤醒监听 goroutine,ctx 为 Background 时 每个订阅者永久泄漏一个 goroutine + 一条残留 channel。

Jump to

Keyboard shortcuts

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