Skip to content

Commit 899f7ea

Browse files
committed
remove broken concurrency limiter
1 parent a0b8728 commit 899f7ea

2 files changed

Lines changed: 6 additions & 37 deletions

File tree

nursery.go

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ type nursery struct {
2626
cancel func()
2727
onError func(error)
2828
errors chan error
29-
limiter limiter
3029
goRoutine chan Routine
3130
routinesCount atomic.Int32
3231
}
@@ -37,7 +36,6 @@ func newNursery() *nursery {
3736
cancel: nil,
3837
onError: nil,
3938
errors: make(chan error),
40-
limiter: nil,
4139
goRoutine: make(chan func() error),
4240
}
4341

@@ -60,22 +58,12 @@ func (n *nursery) Go(routine func() error) {
6058
panic("use of nursery after end of block")
6159
}
6260

63-
if n.limiter == nil {
64-
select {
65-
case n.goRoutine <- routine:
66-
// Successfully reused a goroutine.
67-
default:
68-
// No goroutine available, spawn a new one.
69-
n.goNew(routine)
70-
}
71-
} else {
72-
select {
73-
case n.limiter <- struct{}{}:
74-
// We are below our limit.
75-
n.goNew(routine)
76-
case n.goRoutine <- routine:
77-
// Successfully reused a goroutine.
78-
}
61+
select {
62+
case n.goRoutine <- routine:
63+
// Successfully reused a goroutine.
64+
default:
65+
// No goroutine available, spawn a new one.
66+
n.goNew(routine)
7967
}
8068
}
8169

@@ -160,5 +148,3 @@ func Block(block func(n Nursery) error, opts ...BlockOption) (err error) {
160148

161149
return err
162150
}
163-
164-
type limiter chan struct{}

options.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,3 @@ func WithIgnoreErrors() BlockOption {
7171
n.onError = func(err error) {}
7272
}
7373
}
74-
75-
// WithMaxGoroutines returns a nursery block option that limits the maximum
76-
// number of goroutine running concurrently. If max is zero, number of goroutine
77-
// is unlimited. This function panics if max is negative.
78-
func WithMaxGoroutines(max int) BlockOption {
79-
return func(n *nursery) {
80-
if max < 0 {
81-
panic("max goroutine option must be a non negative integer")
82-
} else if max == 0 {
83-
n.limiter = nil
84-
return
85-
}
86-
87-
// +1 because block function is a routine also.
88-
n.limiter = make(chan struct{}, max+1)
89-
}
90-
}

0 commit comments

Comments
 (0)