diff --git a/throttle.go b/throttle.go index a7134da..8b8059d 100644 --- a/throttle.go +++ b/throttle.go @@ -18,9 +18,9 @@ func NewThrottle(n int) Throttle { return Throttle{adm: make(chan struct{}, n)} } -// Enter blocks until a slot is available in t, then returns a [Leaver] that +// enter blocks until a slot is available in t, then returns a [Leaver] that // the caller must execute to return the slot when it is no longer in use. -func (t Throttle) Enter() Leaver { +func (t Throttle) enter() leaver { if t.adm == nil { return func() {} } @@ -33,21 +33,21 @@ func (t Throttle) Enter() Leaver { } } -// A Leaver returns an in-use throttle slot to its underlying [Throttle]. +// A leaver returns an in-use throttle slot to its underlying [Throttle]. // It is safe to call a Leaver multiple times; the slot will only be returned // once. -type Leaver func() +type leaver func() // Leave returns the slot to its [Throttle]. This is a legibility alias for // calling f. -func (f Leaver) Leave() { f() } +func (f leaver) Leave() { f() } // Limit returns a function that starts each [Task] passed to it in g, // respecting the rate limit imposed by t. Each call to Limit yields a fresh // start function, and all the functions returned share the capacity of t. func (t Throttle) Limit(g *Group) func(Task) { return func(task Task) { - slot := t.Enter() + slot := t.enter() g.Go(func() error { defer slot.Leave() return task()