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 60
60
done chan struct {}
61
61
62
62
stats * safeStats
63
+
64
+ spawnCancel context.CancelFunc
63
65
}
64
66
option [PT Item [T ], T any ] func (p * Pool [PT , T ])
65
67
)
@@ -202,7 +204,9 @@ func New[PT Item[T], T any](
202
204
onChange : p .trace .OnChange ,
203
205
}
204
206
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 )
206
210
207
211
return p
208
212
}
@@ -512,6 +516,9 @@ func (p *Pool[PT, T]) Close(ctx context.Context) (finalErr error) {
512
516
})
513
517
}()
514
518
519
+ // canceling spawner (and any underlying createItem calls)
520
+ p .spawnCancel ()
521
+
515
522
// Only closing done channel.
516
523
// Due to multiple senders queue is not closed here,
517
524
// 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