Documentation
¶
Overview ¶
Package syncx 并发编排原语(stdlib-only):按键在飞闸门 + 按序扇出收集。 收编自消费方手写形态——LLM 按模型名限在飞(429 风暴治理)与「按 index 写 结果免锁」的并行扇出样板。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type KeyedGate ¶
type KeyedGate struct {
// contains filtered or unexported fields
}
KeyedGate 按键在飞上限闸门(并发安全;channel 令牌先到先得;键集由调用方 保证有界——如按模型名/租户名,键量级恒小不回收)。
func NewKeyedGate ¶
NewKeyedGate 构造;cap<=0 = 不限(Acquire 直通零开销)。
type Slot ¶ added in v0.5.0
type Slot[T any] struct { Val T // Err 正常错误,或 panic 收编的 *async.PanicError。 Err error // Panicked 历史兼容字段:panic 原始 payload。新代码改用 // errors.As(&async.PanicError) 读 Err。 // // Deprecated: v0.7.0 起由 Slot.Err 承载。 Panicked any }
Slot 是 FanInErr 的逐槽结果:Val/Err 为 fn 的正常返回;fn panic 时 Err 承载 *async.PanicError(errors.As 可辨、携带栈,#12)且 Val 为零值。 Panicked 保留原始 payload(兼容字段,Deprecated——改用 errors.As(Slot.Err))。
func FanInErr ¶ added in v0.5.0
FanInErr 逐槽错误变体:并行执行 fn(0..n-1)(fn 可返回 error),全部完成后 按 index 序返回逐槽结果。fn 正常返回 → Val/Err 如实记录;fn panic → 该槽 Err=*async.PanicError(v0.7.0 起统一收编,errors.As 可辨、携带栈;Panicked 同写原始 payload,已 Deprecated)、Val 零值,并经 ReportPanic 上报——不再 静默(FanIn 契约保留不动,供无 error 形态的轻量路径)。n<=0 返回空切片。
func FanInLimit ¶ added in v0.12.0
FanInLimit 是 FanInErr 的受限并发变体(#23):n 槽结果语义不变,内部固定 w = min(limit, n) 个 worker 经原子计数器拉取 index 执行——goroutine O(w), 供「n 可达数十以上、fn 是有成本 IO(DB/远端查询)」的 fan-out 限并发, 防下游过载(收编消费方手写的 channel 信号量样板)。其余语义与 FanInErr 一致:按 index 序返回逐槽结果、panic 进该槽 Err(*async.PanicError)并 ReportPanic 上报。limit<=0 = 不设上限(等价 FanInErr 行为)。