Skip to content

Add ChanToSlices helper for safely draining multi-output channels - #504

Open
cinar wants to merge 1 commit into
masterfrom
worktree-agent-aae799e847daa53b5
Open

Add ChanToSlices helper for safely draining multi-output channels#504
cinar wants to merge 1 commit into
masterfrom
worktree-agent-aae799e847daa53b5

Conversation

@cinar

@cinar cinar commented Sep 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • helper.DuplicateWithContext fans 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).
  • Adds helper.ChanToSlices(chans ...<-chan T) [][]T, a general-purpose (not test-only) helper that drains each channel concurrently on its own goroutine via a sync.WaitGroup and returns the collected slices in the same order as the input channels, matching the style of the existing helper.ChanToSlice.
  • Documents the unbuffered/must-drain-concurrently hazard directly on DuplicateWithContext's doc comment, pointing at ChanToSlices as the supported safe way to consume its outputs.
  • Purely additive: no existing indicator signatures/behavior changed, no README or legal/disclaimer content touched, nothing moved between examples/ and strategy/.

Test plan

  • Added helper/chan_to_slices_test.go covering: 2 channels, 4 channels (via DuplicateWithContext), and a goroutine-leak/deadlock check modeled on TestCciCancellation in trend/cci_test.go (unbuffered channels, runtime.NumGoroutine() before/after, time.Sleep + runtime.GC(), plus a time.After deadlock 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

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-commenter

Copy link
Copy Markdown

Codecov Report

βœ… All modified and coverable lines are covered by tests.
βœ… Project coverage is 91.97%. Comparing base (74b9529) to head (48beaf2).
⚠️ Report is 1 commits behind head on master.

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.
πŸ“’ Have feedback on the report? Share it here.

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants