Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type GoFunc ¶
type GoFunc[T any] func(ctx context.Context, region *LimitedRegion, t T) error
GoFunc represents a function that can be invoked by Go.
type LimitedGroup ¶
type LimitedGroup struct {
// contains filtered or unexported fields
}
A LimitedGroup is a collection of goroutines working on subtasks that are part of the same overall task.
func LimitGroup ¶
LimitGroup returns a new LimitedGroup and an associated Context derived from ctx.
The number of active goroutines in this group is limited to the given limit. A negative value indicates no limit.
The derived Context is canceled the first time a function passed to Go returns a non-nil error or the first time Wait returns, whichever occurs first.
func (*LimitedGroup) Go ¶
func (g *LimitedGroup) Go(f func() error)
Go calls the given function in a new goroutine. It blocks until the new goroutine can be added without the number of active goroutines in the group exceeding the configured limit.
The first call to return a non-nil error cancels the group's context. After which, any subsequent calls to Go will not execute their given function. The error will be returned by Wait.
func (*LimitedGroup) Wait ¶
func (g *LimitedGroup) Wait() error
Wait blocks until all function calls from the Go method have returned, then returns the first non-nil error (if any) from them.
type LimitedRegion ¶
type LimitedRegion struct {
// contains filtered or unexported fields
}
LimitedRegion provides a way to bound concurrent access to a code block.
func LimitRegion ¶
func LimitRegion(ctx context.Context, limiter *semaphore.Weighted) *LimitedRegion
LimitRegion creates a new LimitedRegion.
func (*LimitedRegion) End ¶
func (lr *LimitedRegion) End()
End ends the region with concurrency limit.
func (*LimitedRegion) Start ¶
func (lr *LimitedRegion) Start() error
Start starts the region with concurrency limit.
type Merge ¶
type Merge[T any] struct { // contains filtered or unexported fields }
Merge represents merge operations on items. The state transfer is shown as below:
+----------+ | Start +--------+-------------+ +----+-----+ | | | | | v v v +----+-----+ +----+----+ +----+----+ +-------+ Prepare +<--+ Pending +-->+ Waiting | | +----+-----+ +---------+ +----+----+ | | | | v | | + ---+---- + | On Error | Resolve | | | + ---+---- + | | | | | v | | +----+-----+ | +------>+ Complete +<---------------------+ +----+-----+ | v +----+-----+ | End | +----------+
type Once ¶
type Once struct {
// contains filtered or unexported fields
}
Once is an object that will perform exactly one action. Unlike sync.Once, this Once allows the action to have return values.
func (*Once) Do ¶
Do calls the function f if and only if Do is being called first time or all previous function calls are cancelled, deadline exceeded, or panicking. When `once.Do(ctx, f)` is called multiple times, the return value of the first call of the function f is stored, and is directly returned for other calls. Besides the return value of the function f, including the error, Do returns true if the function f passed is called first and is not cancelled, deadline exceeded, or panicking. Otherwise, returns false.
type OnceOrRetry ¶
type OnceOrRetry struct {
// contains filtered or unexported fields
}
OnceOrRetry is an object that will perform exactly one success action.
func (*OnceOrRetry) Do ¶
func (o *OnceOrRetry) Do(f func() error) error
OnceOrRetry calls the function f if and only if Do is being called for the first time for this instance of Once or all previous calls to Do are failed.
type Pool ¶
type Pool[T any] struct { // New optionally specifies a function to generate a value when Get would // otherwise return nil. // It may not be changed concurrently with calls to Get. New func() T // contains filtered or unexported fields }
Pool is a scalable pool with items identified by keys.