conc icon indicating copy to clipboard operation
conc copied to clipboard

Add CancelOnError option to ContextPool

Open camdencheek opened this issue 3 years ago • 3 comments

This adds the WithCancelOnError() configuration method to ContextPool and ResultContextPool, and changes the default behavior to not cancel the pool's context on error.

ContextPool initially canceled by default because otherwise, it's no different than an ErrorPool that captures a context from its environment. However, doing this by default is surprising and should be explicitly opt-in.

camdencheek avatar Jan 06 '23 23:01 camdencheek

Codecov Report

Merging #23 (f13fcd7) into main (df84427) will increase coverage by 0.01%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #23      +/-   ##
==========================================
+ Coverage   99.42%   99.44%   +0.01%     
==========================================
  Files          10       10              
  Lines         350      358       +8     
==========================================
+ Hits          348      356       +8     
  Misses          2        2              
Impacted Files Coverage Δ
pool/context_pool.go 100.00% <100.00%> (ø)
pool/result_context_pool.go 100.00% <100.00%> (ø)
waitgroup.go 100.00% <0.00%> (ø)

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

codecov-commenter avatar Jan 06 '23 23:01 codecov-commenter

Another idea - if we eventually add various cancel behaviours, should we offer a consistent naming scheme like CancelXYZ? eg

  • CancelOnError() (renamed FailFast)
  • CancelAfterErrors(n int)
  • Cancel()

bobheadxi avatar Jan 07 '23 00:01 bobheadxi

That makes sense to me. Additionally, WithCancelOnError() is a little more verbose, but much more clear to readers what it actually does. I'd need to take a look at the docs for WithFastFail().

camdencheek avatar Jan 07 '23 00:01 camdencheek