Documentation
¶
Index ¶
Constants ¶
const (
// DefaultLimit is the default concurrency limit
DefaultLimit = 100
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConcurrencyLimiter ¶
type ConcurrencyLimiter struct {
// 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
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
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) Wait ¶
func (c *ConcurrencyLimiter) Wait()
Wait will block all the previously Executed jobs completed running.
IMPORTANT: calling the Wait function while keep calling Execute leads to
un-desired race conditions