feat: catalogue generate now rate limits

Closes coop-cloud/organising#231.
This commit is contained in:
2021-11-03 06:53:19 +01:00
parent 08aca28d9d
commit e4e606efb0
2 changed files with 25 additions and 0 deletions

20
pkg/limit/limit.go Normal file
View File

@ -0,0 +1,20 @@
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
}