X-Git-Url: https://git.arvados.org/lightning.git/blobdiff_plain/3bcdc5d862b0924ef34d72e1596cb96663a9bd83..4c2919861ddfc4c48588cf3336f99efea94eee16:/throttle.go diff --git a/throttle.go b/throttle.go index ce3279dd33..8b087eeae2 100644 --- a/throttle.go +++ b/throttle.go @@ -19,7 +19,12 @@ type throttle struct { } func (t *throttle) Acquire() { - t.setupOnce.Do(func() { t.ch = make(chan bool, t.Max) }) + t.setupOnce.Do(func() { + if t.Max < 1 { + panic("throttle.Max < 1") + } + t.ch = make(chan bool, t.Max) + }) t.wg.Add(1) t.ch <- true } @@ -48,6 +53,7 @@ func (t *throttle) Wait() error { func (t *throttle) Go(f func() error) error { t.Acquire() if t.Err() != nil { + t.Release() return t.Err() } go func() {