Documentation
¶
Overview ¶
Package batch 提供批量任务的有界并发、热更新分类容量、集群共享租约和异常隔离能力。
Index ¶
- func Do(ctx context.Context, work func(context.Context) error) error
- func Map[T, R any](ctx context.Context, items []T, options Options, ...) ([]Result[R], Summary, error)
- func MapObserved[T, R any](ctx context.Context, items []T, options Options, ...) ([]Result[R], Summary, error)
- func Run[T any](ctx context.Context, items []T, options Options, ...) ([]Result[struct{}], Summary, error)
- type LeaseLimiter
- type Options
- type PanicError
- type Pool
- type PoolSnapshot
- type Result
- type Summary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Map ¶
func Map[T, R any](ctx context.Context, items []T, options Options, work func(context.Context, T) (R, error)) ([]Result[R], Summary, error)
Map 以稳定输入顺序返回结果;单项失败和 panic 不会中断其他已提交任务。
Types ¶
type LeaseLimiter ¶
type PanicError ¶
PanicError 表示任务发生 panic;堆栈只用于服务端诊断,不应直接返回给客户端。
func (*PanicError) Error ¶
func (e *PanicError) Error() string
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool 在多个批量操作之间共享并发容量,避免并发请求叠加突破上游保护阈值。
func NewChildPool ¶
NewChildPool 创建分类并发池;任务先取得分类容量,再进入父级全局池。
func NewSharedChildPool ¶
func NewSharedChildPool(limit int, limiter LeaseLimiter, key string, parent *Pool) *Pool
NewSharedChildPool 创建同时受分类集群租约和父级总容量约束的并发池。
func NewSharedPool ¶
func NewSharedPool(limit int, limiter LeaseLimiter, key string) *Pool
func (*Pool) Snapshot ¶
func (p *Pool) Snapshot() PoolSnapshot
func (*Pool) UpdateJitter ¶
UpdateJitter 热更新任务进入并发池前的随机延迟上限;零表示关闭。
func (*Pool) UpdateLimit ¶
UpdateLimit 热更新并发上限;降低上限不会中断正在执行的任务。
Click to show internal directories.
Click to hide internal directories.