File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change 6060 done chan struct {}
6161
6262 stats * safeStats
63+
64+ spawnCancel context.CancelFunc
6365 }
6466 option [PT Item [T ], T any ] func (p * Pool [PT , T ])
6567)
@@ -202,7 +204,9 @@ func New[PT Item[T], T any](
202204 onChange : p .trace .OnChange ,
203205 }
204206
205- go p .spawnItems (xcontext .ValueOnly (ctx ))
207+ var spawnCtx context.Context
208+ spawnCtx , p .spawnCancel = xcontext .WithCancel (xcontext .ValueOnly (ctx ))
209+ go p .spawnItems (spawnCtx )
206210
207211 return p
208212}
@@ -512,6 +516,9 @@ func (p *Pool[PT, T]) Close(ctx context.Context) (finalErr error) {
512516 })
513517 }()
514518
519+ // canceling spawner (and any underlying createItem calls)
520+ p .spawnCancel ()
521+
515522 // Only closing done channel.
516523 // Due to multiple senders queue is not closed here,
517524 // we're just making sure to drain it fully to close any existing item.
You can’t perform that action at this time.
0 commit comments