erxgroup

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2025 License: MIT Imports: 6 Imported by: 1

Documentation

Overview

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 提供 errgroup 的泛型包装,支持类型安全的自定义错误处理 允许使用自定义错误类型而非标准 error 接口,同时保持 errgroup 语义

Index

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 ErrorType 是内部包中定义的约束的别名

type Group

type Group[E ErrorType] struct {
	// contains filtered or unexported fields
}

Group wraps errgroup.Group with type-safe custom error handling Provides generic error type E instead of standard error interface Maintains context cancellation and goroutine synchronization semantics

Group 使用类型安全的自定义错误处理包装 errgroup.Group 提供泛型错误类型 E 而不是标准 error 接口 保持上下文取消和协程同步语义

func NewGroup

func NewGroup[E ErrorType](ctx context.Context) *Group[E]

NewGroup creates generic errgroup with custom error type Context cancels when first error occurs or parent context cancels

NewGroup 创建带有自定义错误类型的泛型 errgroup 当第一个错误发生或父上下文取消时,上下文会被取消

func (*Group[E]) Go

func (G *Group[E]) Go(run func(ctx context.Context) E)

Go starts goroutine within the group Converts custom error E to standard error when task fails Task receives shared cancellable context

Go 在组内启动协程 当任务失败时将自定义错误 E 转换为标准 error 任务接收共享的可取消上下文

func (*Group[E]) SetLimit

func (G *Group[E]) SetLimit(n int)

SetLimit restricts concurrent goroutines count Must be invoked before first Go and TryGo invocation

SetLimit 限制并发协程数量 必须在第一次 Go 或 TryGo 调用之前调用

func (*Group[E]) TryGo

func (G *Group[E]) TryGo(run func(ctx context.Context) E) bool

TryGo attempts to start goroutine within the group Returns false if goroutine limit reached, true if started Same error handling as Go method

TryGo 尝试在组内启动协程 如果达到协程限制则返回 false,如果启动则返回 true 与 Go 方法相同的错误处理

func (*Group[E]) Wait

func (G *Group[E]) Wait() E

Wait blocks awaiting goroutine completion and returns first error Uses errors.As to convert standard error back to custom type E Returns zero value when execution succeeds

Wait 阻塞直到所有协程完成并返回第一个错误 使用 errors.As 将标准 error 转换回自定义类型 E 当所有协程成功时返回零值

Jump to

Keyboard shortcuts

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