abra/pkg/limit/limit.go
decentral1se e4e606efb0
All checks were successful
continuous-integration/drone/push Build is passing
feat: catalogue generate now rate limits
Closes coop-cloud/organising#231.
2021-11-03 06:53:38 +01:00

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
}