Documentation
¶
Overview ¶
Package egobatch: Generic batch task processing with type-safe error handling Provides Task and TaskBatch types enabling concurrent batch operations with custom error types Supports result filtering (OkTasks/WaTasks) and flexible result transformation via Flatten
egobatch: 具有类型安全错误处理的泛型批量任务处理 提供 Task 和 TaskBatch 类型,支持使用自定义错误类型的并发批量操作 支持结果过滤(OkTasks/WaTasks)和通过 Flatten 进行灵活的结果转换
Index ¶
- type ErrorType
- type Task
- type TaskBatch
- func (t *TaskBatch[A, R, E]) EgoRun(ego *erxgroup.Group[E], run func(ctx context.Context, arg A) (R, E))
- func (t *TaskBatch[A, R, E]) GetRun(idx int, run func(ctx context.Context, arg A) (R, E)) func(ctx context.Context) E
- func (t *TaskBatch[A, R, E]) SetGlide(glide bool)
- func (t *TaskBatch[A, R, E]) SetWaCtx(waCtx func(err error) E)
- type TaskOutput
- type TaskOutputList
- func (rs TaskOutputList[ARG, RES, E]) OkCount() int
- func (rs TaskOutputList[ARG, RES, E]) OkList() TaskOutputList[ARG, RES, E]
- func (rs TaskOutputList[ARG, RES, E]) OkResults() []RES
- func (rs TaskOutputList[ARG, RES, E]) WaCount() int
- func (rs TaskOutputList[ARG, RES, E]) WaList() TaskOutputList[ARG, RES, E]
- func (rs TaskOutputList[ARG, RES, E]) WaReasons() []E
- type Tasks
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrorType ¶
type ErrorType = constraint.ErrorType
ErrorType is an alias to the constraint defined in the internal package Enables type-safe error handling with comparable custom error types
ErrorType 是内部包中定义的约束的别名 支持使用可比较的自定义错误类型进行类型安全的错误处理
type Task ¶
type Task[A any, R any, E ErrorType] struct { Arg A // Task input argument // 任务输入参数 Res R // Task result value // 任务结果值 Erx E // Task error (nil when success) // 任务错误(成功时为 nil) }
Task represents a single task with argument, result, and error Generic type supporting any argument type A, result type R, and error type E
Task 代表单个任务,包含参数、结果和错误 泛型类型支持任意参数类型 A、结果类型 R 和错误类型 E
type TaskBatch ¶
type TaskBatch[A any, R any, E ErrorType] struct { Tasks Tasks[A, R, E] // Task collection with arguments and results // 任务集合,包含参数和结果 Glide bool // Glide mode flag: false=fail-fast, true=independent tasks // 平滑模式标志:false=快速失败,true=独立任务 // contains filtered or unexported fields }
TaskBatch manages batch task execution with concurrent processing Supports glide mode enabling independent task execution and fail-fast mode Provides context error handling and result aggregation capabilities
TaskBatch 管理批量任务的并发执行 支持平滑模式,可以独立执行任务或快速失败 提供上下文错误处理和结果聚合能力
func NewTaskBatch ¶
NewTaskBatch creates batch task engine with starting arguments Each argument becomes a task with zero-initialized result and error Default glide mode is false (fail-fast mode)
NewTaskBatch 使用初始参数创建批量任务处理器 每个参数成为一个任务,结果和错误初始化为零值 默认平滑模式是 false(快速失败行为)
func (*TaskBatch[A, R, E]) EgoRun ¶
func (t *TaskBatch[A, R, E]) EgoRun(ego *erxgroup.Group[E], run func(ctx context.Context, arg A) (R, E))
EgoRun demonstrates GetRun usage with inversion-of-control pattern When task logic is complex and scheduling logic is simple, pass scheduling engine as argument Auto schedules tasks into the provided errgroup
EgoRun 演示 GetRun 使用方式,采用控制反转模式 当任务逻辑较重而调度逻辑较轻时,将调度器作为参数传入 自动将所有任务调度到提供的 errgroup 中
func (*TaskBatch[A, R, E]) GetRun ¶
func (t *TaskBatch[A, R, E]) GetRun(idx int, run func(ctx context.Context, arg A) (R, E)) func(ctx context.Context) E
GetRun creates execution function at given index compatible with errgroup.Go Index must be valid (invoking code controls iteration count as basic contract) Returns wrapped function handling context cancellation and error propagation
GetRun 在给定索引处创建与 errgroup.Go 兼容的执行函数 索引必须有效(调用者控制迭代次数作为基本约定) 返回处理上下文取消和错误传播的包装函数
func (*TaskBatch[A, R, E]) SetGlide ¶
SetGlide configures glide mode When true: tasks execute in independent mode, errors recorded without stopping others When false: first error stops batch execution (fail-fast)
SetGlide 配置平滑模式行为 当为 true:任务独立执行,错误被记录但不停止其他任务 当为 false:第一个错误停止批量执行(快速失败)
type TaskOutput ¶
type TaskOutput[ARG any, RES any, E ErrorType] struct { Arg ARG // Task input argument // 任务输入参数 Res RES // Task result value // 任务结果值 Erx E // Task error (nil when success) // 任务错误(成功时为 nil) }
TaskOutput represents single task execution outcome with argument, result, and error Like Task but designed as simple data container without batch processing logic Used when returning task results without needing complete Task batch capabilities
TaskOutput 代表单个任务执行结果,包含参数、结果和错误 类似 Task 但设计为简单数据传输对象,不包含批处理逻辑 用于返回任务结果而不需要完整的 Task 批处理能力
func NewOkTaskOutput ¶
func NewOkTaskOutput[ARG any, RES any, E ErrorType](arg ARG, res RES) *TaskOutput[ARG, RES, E]
NewOkTaskOutput creates success task output with result Error field initialized to zero value indicating success
NewOkTaskOutput 创建成功的任务输出,包含结果 错误字段初始化为零值,表示成功
func NewWaTaskOutput ¶
func NewWaTaskOutput[ARG any, RES any, E ErrorType](arg ARG, erx E) *TaskOutput[ARG, RES, E]
NewWaTaskOutput creates failed task output with error Result field initialized to zero value as task failed
NewWaTaskOutput 创建失败的任务输出,包含错误 结果字段初始化为零值,因为任务失败
type TaskOutputList ¶
type TaskOutputList[ARG any, RES any, E ErrorType] []*TaskOutput[ARG, RES, E]
TaskOutputList is a collection of task outputs supporting filtering and aggregation Provides methods to separate success and failed results Enables result extraction and error collection patterns
TaskOutputList 是任务输出的集合,支持过滤和聚合 提供分离成功和失败结果的方法 支持结果提取和错误收集模式
func (TaskOutputList[ARG, RES, E]) OkCount ¶
func (rs TaskOutputList[ARG, RES, E]) OkCount() int
OkCount counts success task outputs Returns count of outputs on success
OkCount 统计成功的任务输出 返回成功的输出数量
func (TaskOutputList[ARG, RES, E]) OkList ¶
func (rs TaskOutputList[ARG, RES, E]) OkList() TaskOutputList[ARG, RES, E]
OkList filters and returns outputs that completed with success Returns subset on success
OkList 过滤并返回成功完成的输出 返回成功的子集
func (TaskOutputList[ARG, RES, E]) OkResults ¶
func (rs TaskOutputList[ARG, RES, E]) OkResults() []RES
OkResults extracts result values from success outputs Returns slice containing just results from outputs without errors
OkResults 从成功的输出中提取结果值 返回仅包含无错误输出的结果切片
func (TaskOutputList[ARG, RES, E]) WaCount ¶
func (rs TaskOutputList[ARG, RES, E]) WaCount() int
WaCount counts failed task outputs Returns count of outputs when error occurs
WaCount 统计失败的任务输出 返回出错的输出数量
func (TaskOutputList[ARG, RES, E]) WaList ¶
func (rs TaskOutputList[ARG, RES, E]) WaList() TaskOutputList[ARG, RES, E]
WaList filters and returns outputs that failed with errors Returns subset when error occurs
WaList 过滤并返回失败的输出 返回出错的子集
func (TaskOutputList[ARG, RES, E]) WaReasons ¶
func (rs TaskOutputList[ARG, RES, E]) WaReasons() []E
WaReasons extracts error values from failed outputs Returns slice containing just errors from outputs with failures
WaReasons 从失败的输出中提取错误值 返回仅包含失败输出的错误切片
type Tasks ¶
Tasks is a slice of Task pointers supporting batch operations Provides filtering and transformation methods on task collections
Tasks 是 Task 指针切片,支持批量操作 提供任务集合的过滤和转换方法
func (Tasks[A, R, E]) Flatten ¶
func (tasks Tasks[A, R, E]) Flatten(newWaFunc func(arg A, erx E) R) []R
Flatten transforms task results into flat slice with error handling Uses newWaFunc to convert failed tasks into result type R Returns slice of results mixing success cases and transformed errors
Flatten 将任务结果转换成扁平切片并处理错误 使用 newWaFunc 将失败的任务转换为结果类型 R 返回混合成功结果和转换后错误的结果切片
Directories
¶
| Path | Synopsis |
|---|---|
|
Package erxgroup provides generic wrapper around errgroup with type-safe custom error handling Enables using custom error types instead of standard error interface while maintaining errgroup semantics
|
Package erxgroup provides generic wrapper around errgroup with type-safe custom error handling Enables using custom error types instead of standard error interface while maintaining errgroup semantics |
|
internal
|
|
|
demos/demo1x
command
|
|
|
demos/demo2x
command
|
|
|
demos/demo3x
command
|
|
|
examples/example1
Package example1 demonstrates basic batch task processing patterns Shows guest and order processing with error handling
|
Package example1 demonstrates basic batch task processing patterns Shows guest and order processing with error handling |
|
examples/example2
Package example2 demonstrates nested batch processing patterns Shows class, student, and subject score aggregation with error handling
|
Package example2 demonstrates nested batch processing patterns Shows class, student, and subject score aggregation with error handling |
|
examples/example3
Package example3 demonstrates multi-step pipeline processing patterns Shows cascading task execution with nested batch operations
|
Package example3 demonstrates multi-step pipeline processing patterns Shows cascading task execution with nested batch operations |
|
utils
Package utils provides common utilities 包 utils 提供通用工具
|
Package utils provides common utilities 包 utils 提供通用工具 |