feat(pool): add EachCtx for cancellable fan-out - #352
Conversation
Each has no way to observe cancellation, so a fan-out scanner (full port sweep, directory brute-force) keeps draining its whole queue even after ctrl-c or -max-time fires. EachCtx takes a context and stops feeding workers once it's cancelled, while still handing the ctx to the callback so an in-flight item can bail out too. Each is now a thin wrapper over EachCtx with context.Background(), so existing callers are unaffected until they opt in.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #352 +/- ##
=======================================
Coverage ? 54.76%
=======================================
Files ? 81
Lines ? 6880
Branches ? 0
=======================================
Hits ? 3768
Misses ? 2842
Partials ? 270 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
pr summary2 files changed (+71 -4)
|
vmfunc
left a comment
There was a problem hiding this comment.
ctx.Err() check sits right before fn so a cancel stops new pulls but never kills a worker mid-item, which is the behavior you want on -max-time. defer wg.Done() on every exit path so the early return can't leak, and Each collapsing to the Background() wrapper is a no-op on the old path. in.
Each has no way to stop early: once -max-time expires or ctrl-c fires, in-flight workers keep draining the whole queue before the pool returns. EachCtx takes a context and stops handing out new items once it's cancelled, while workers already running finish their current item rather than being killed mid-write. Each is now a thin wrapper over EachCtx with context.Background().