waitgroup

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: Apache-2.0 Imports: 3 Imported by: 33

Documentation

Overview

Package waitgroup implements SafeWaitGroup wrap of sync.WaitGroup. Add with positive delta when waiting will fail, to prevent sync.WaitGroup race issue.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RateLimitedSafeWaitGroup added in v0.27.0

type RateLimitedSafeWaitGroup struct {
	// contains filtered or unexported fields
}

RateLimitedSafeWaitGroup must not be copied after first use.

func (*RateLimitedSafeWaitGroup) Add added in v0.27.0

func (wg *RateLimitedSafeWaitGroup) Add(delta int) error

Add adds delta, which may be negative, similar to sync.WaitGroup. If Add with a positive delta happens after Wait, it will return error, which prevent unsafe Add.

func (*RateLimitedSafeWaitGroup) Done added in v0.27.0

func (wg *RateLimitedSafeWaitGroup) Done()

Done decrements the WaitGroup counter, rate limiting is applied only when the wait group is in waiting mode.

func (*RateLimitedSafeWaitGroup) Wait added in v0.27.0

func (wg *RateLimitedSafeWaitGroup) Wait(limiterFactory RateLimiterFactoryFunc) (int, int, error)

Wait blocks until the WaitGroup counter is zero or a hard limit has elapsed. It returns the number of active request(s) accounted for at the time Wait has been invoked, number of request(s) that have drianed (done using the wait group immediately before Wait returns). Ideally, the both numbers returned should be equal, to indicate that all request(s) using the wait group have released their lock.

type RateLimiter added in v0.27.0

type RateLimiter interface {
	Wait(ctx context.Context) error
}

RateLimiter abstracts the rate limiter used by RateLimitedSafeWaitGroup. The implementation must be thread-safe.

type RateLimiterFactoryFunc added in v0.27.0

type RateLimiterFactoryFunc func(count int) (RateLimiter, context.Context, context.CancelFunc)

RateLimiterFactoryFunc is used by the RateLimitedSafeWaitGroup to create a new instance of a RateLimiter that will be used to rate limit the return rate of the active number of request(s). 'count' is the number of requests in flight that are expected to invoke 'Done' on this wait group.

type SafeWaitGroup

type SafeWaitGroup struct {
	// contains filtered or unexported fields
}

SafeWaitGroup must not be copied after first use.

func (*SafeWaitGroup) Add

func (wg *SafeWaitGroup) Add(delta int) error

Add adds delta, which may be negative, similar to sync.WaitGroup. If Add with a positive delta happens after Wait, it will return error, which prevent unsafe Add.

func (*SafeWaitGroup) Done

func (wg *SafeWaitGroup) Done()

Done decrements the WaitGroup counter.

func (*SafeWaitGroup) Wait

func (wg *SafeWaitGroup) Wait()

Wait blocks until the WaitGroup counter is zero.

Jump to

Keyboard shortcuts

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