Add ChanToSlices helper for safely draining multi-output channels - #504
Open
cinar wants to merge 1 commit into
Open
Add ChanToSlices helper for safely draining multi-output channels#504cinar wants to merge 1 commit into
cinar wants to merge 1 commit into
Conversation
DuplicateWithContext fans out into unbuffered channels that must all be drained concurrently or the producer deadlocks. Several engineers hit this independently while testing multi-output indicators (Kdj, StochasticOscillator, AccelerationBands). Add helper.ChanToSlices to drain N channels concurrently via goroutines, and document the hazard on DuplicateWithContext pointing at it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xv4stuAb6WuQ8rPZ4cupLp
Codecov Reportβ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #504 +/- ##
==========================================
+ Coverage 91.96% 91.97% +0.01%
==========================================
Files 233 234 +1
Lines 7719 7730 +11
==========================================
+ Hits 7099 7110 +11
Misses 531 531
Partials 89 89 β View full report in Codecov by Harness. π New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
helper.DuplicateWithContextfans out into N unbuffered output channels; all of them must be actively drained concurrently or the producer goroutine deadlocks. Several engineers independently hit this while writing tests for multi-output indicators (AccelerationBands,Kdj/SlowStochastic/Stochastic,StochasticOscillator).helper.ChanToSlices(chans ...<-chan T) [][]T, a general-purpose (not test-only) helper that drains each channel concurrently on its own goroutine via async.WaitGroupand returns the collected slices in the same order as the input channels, matching the style of the existinghelper.ChanToSlice.DuplicateWithContext's doc comment, pointing atChanToSlicesas the supported safe way to consume its outputs.examples/andstrategy/.Test plan
helper/chan_to_slices_test.gocovering: 2 channels, 4 channels (viaDuplicateWithContext), and a goroutine-leak/deadlock check modeled onTestCciCancellationintrend/cci_test.go(unbuffered channels,runtime.NumGoroutine()before/after,time.Sleep+runtime.GC(), plus atime.Afterdeadlock guard).go build ./...go vet ./...gofmt -l .β no output from files touched by this change (pre-existing unformatted files elsewhere are unrelated and unchanged by this PR)go test ./...β all packages passπ€ Generated with Claude Code
https://claude.ai/code/session_01Xv4stuAb6WuQ8rPZ4cupLp