Documentation ¶
Index ¶
Constants ¶
const (
DefaultConcurrencyLimitIO = 4
)
const (
// DefaultLimit is the default concurrency limit
DefaultLimit = 100
)
Variables ¶
var ( // appending a callback to a closed limiter ErrorClosed = errors.New("limiter closed") ErrorSubroutinePanic = errors.New("goroutine panic") )
Functions ¶
This section is empty.
Types ¶
type ConcurrencyLimiter ¶
type ConcurrencyLimiter struct { RecoverPanics bool // recover from panics in the subroutines (keeping the process running) // contains filtered or unexported fields }
ConcurrencyLimiter object
func NewConcurrencyLimiter ¶
func NewConcurrencyLimiter(limit int) *ConcurrencyLimiter
NewConcurrencyLimiter allocates a new ConcurrencyLimiter
func (*ConcurrencyLimiter) Execute ¶
func (c *ConcurrencyLimiter) Execute(job func()) (int, error)
Execute adds a function to the execution queue. if num of go routines allocated by this instance is < limit launch a new go routine to execute job else wait until a go routine becomes available
func (*ConcurrencyLimiter) ExecuteWithTicket ¶
func (c *ConcurrencyLimiter) ExecuteWithTicket(job func(ticket int)) (int, error)
ExecuteWithTicket adds a job into an execution queue and returns a ticket id. if num of go routines allocated by this instance is < limit launch a new go routine to execute job else wait until a go routine becomes available
func (*ConcurrencyLimiter) GetNumInProgress ¶
func (c *ConcurrencyLimiter) GetNumInProgress() int32
GetNumInProgress returns a (racy) counter of how many go routines are active right now
func (*ConcurrencyLimiter) WaitAndClose ¶
func (c *ConcurrencyLimiter) WaitAndClose() error
WaitAndClose will block until all the previously Executed jobs completed running. New tasks won't be allow
IMPORTANT: calling the Wait function while keep calling Execute leads to
un-desired race conditions
type Concurrently ¶
type Concurrently struct {
// contains filtered or unexported fields
}
Concurrently - execute tasks (IO) concurrently, keep track of the first error atomically
func NewConcurrencyLimiterForIO ¶
func NewConcurrencyLimiterForIO(limit int) *Concurrently
func (*Concurrently) Execute ¶
func (c *Concurrently) Execute(job func()) (int, error)
func (*Concurrently) FirstErrorGet ¶
func (c *Concurrently) FirstErrorGet() error
func (*Concurrently) FirstErrorStore ¶
func (c *Concurrently) FirstErrorStore(e error) (bool, error)
func (*Concurrently) WaitAndClose ¶
func (c *Concurrently) WaitAndClose() error