Documentation
¶
Overview ¶
Package pipeline 提供类型安全的多阶段流水线:数据经过多个 Stage 顺序处理, 每个 Stage 可配置并发 worker 数(扇出)、带背压(有界 channel)。
典型场景:
- ETL 数据处理:读取 → 解析 → 转换 → 写入
- 图片处理:下载 → 解码 → 缩放 → 上传
- 日志处理:采集 → 过滤 → 聚合 → 存储
与 stream/router 区别:
- stream: 单阶段扇出/广播
- router: 按规则路由到不同目标
- pipeline: 多阶段顺序链,每阶段可并发,背压传导
纯标准库、泛型。
Index ¶
- func Merge[T any](ctx context.Context, channels ...<-chan T) <-chan T
- func Pipe[In, Out any](ctx context.Context, input <-chan In, stage Stage[In, Out]) (<-chan Out, <-chan error)
- func Run[In, Out any](ctx context.Context, source <-chan In, stage Stage[In, Out]) ([]Out, error)
- func Source[T any](ctx context.Context, items []T) <-chan T
- func Split[T any](ctx context.Context, input <-chan T, n int) []<-chan T
- type ProcessFunc
- type Stage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Pipe ¶
func Pipe[In, Out any](ctx context.Context, input <-chan In, stage Stage[In, Out]) (<-chan Out, <-chan error)
Pipe 连接两个阶段:从 input channel 读取,经 stage 处理,输出到新 channel。 返回输出 channel 和 error channel。当 input 关闭且所有 worker 完成后,输出 channel 关闭。
Types ¶
type ProcessFunc ¶
ProcessFunc 阶段处理函数。输入一条数据,输出零或多条(通过 emit)。 返回 error 表示致命错误,将终止整个 pipeline。
Click to show internal directories.
Click to hide internal directories.