File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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- }
You can’t perform that action at this time.
0 commit comments