Skip to content

Commit

Permalink
taskgroup: unexport the Enter method of Throttle
Browse files Browse the repository at this point in the history
The interesting part of the API is the Limit method.
Also unexport the Leaver type.
  • Loading branch information
creachadair committed Oct 31, 2024
1 parent 8cb4400 commit 6cba8ab
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions throttle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
}
Expand All @@ -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()
Expand Down

0 comments on commit 6cba8ab

Please sign in to comment.