Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter is used to limit a number of goroutines. Instead of starting the goroutines using `go func()...`, use `limiter.Execute()` After usage, close the limiter using `limiter.Close()`
Limiter will not limit the number of goroutines, but the number of callbacks that are executed at once.
func NewLimiter ¶
NewLimiter creates a new limiter with the given amount of max concurrent running functions. Note, that if maxConcurrent <= 0 is equivalent of constructing a Limiter with maxConcurrent=MAX_INT
func (*Limiter) Close ¶
func (l *Limiter) Close()
Close cleans up the limiter. All running goroutines will be finished, but no new ones can be started. Closing the limiter multiple times will cause a panic
func (*Limiter) Execute ¶
func (l *Limiter) Execute(callback func())
Execute runs the passed function in a goroutines. If the maximum number of goroutines is reached, it is waited until a previously started goroutine (using this limiter) is done. If the limiter is closed and more functions are started, Execute will panic.
func (*Limiter) ExecuteBlocking ¶
func (l *Limiter) ExecuteBlocking(callback func())
ExecuteBlocking runs the passed function blocking. If the maximum number of parallel running functions is reached, the function does not execute the callback and does not return until a slot is free.