All checks were successful
continuous-integration/drone/push Build is passing
Closes coop-cloud/organising#231.
21 lines
474 B
Go
21 lines
474 B
Go
package limit // https://github.com/tidwall/limiter
|
|
|
|
// Limiter is for limiting the number of concurrent operations. This
|
|
type Limiter struct{ sem chan struct{} }
|
|
|
|
// New returns a new Limiter. The limit param is the maximum number of
|
|
// concurrent operations.
|
|
func New(limit int) *Limiter {
|
|
return &Limiter{make(chan struct{}, limit)}
|
|
}
|
|
|
|
// Begin an operation.
|
|
func (l *Limiter) Begin() {
|
|
l.sem <- struct{}{}
|
|
}
|
|
|
|
// End the operation.
|
|
func (l *Limiter) End() {
|
|
<-l.sem
|
|
}
|