Skip to content

Redesign readers to caller-owned channels + error return - #3

Merged
vertoforce merged 2 commits into
masterfrom
streamregex-channel-api-2026-07
Jul 16, 2026
Merged

vertoforce merged 2 commits into
masterfrom
streamregex-channel-api-2026-07

Conversation

@vertoforce

Copy link
Copy Markdown
Owner

Redesigns the two reader functions to a caller-managed style (modeled on go-ioc's GetIOCsReader).

  • BREAKING API CHANGE: FindReader/FindReaderIndex now accept caller-owned channels and return an error instead of returning a channel.
  • Run synchronously (no internal goroutine); never close the channels — the caller owns concurrency, error handling, and channel lifecycle.
  • Return scanner.Err() at EOF so a read failure surfaces instead of looking like a clean EOF; return ctx.Err() on cancellation.
  • FindReaderIndex still emits each index just before its match; caller must drain both channels (buffer indexes by 1) or it deadlocks — documented.
  • Examples, unit tests, and README updated to the new style.

Tests: gofmt/go vet ./... clean, go test -race ./... passes (Go 1.24).

Includes the earlier cleanup fixes from #2 since master does not yet contain them.

🤖 Generated with Claude Code

vertoforce and others added 2 commits July 14, 2026 22:13
…dernize to Go 1.24

- Close the index channel when the scanner goroutine finishes so
  'for range' over it terminates instead of hanging forever; document
  that callers must drain both channels to avoid deadlocking the
  split function.
- Fix ExampleFindReaderIndex's // Output: comment — the example prints
  both match and index ("stream    of [20 32]"), so go test failed.
- Rename steamregexindex(.go|_test.go) -> streamregexindex(.go|_test.go).
- Bump go.mod go directive to 1.24; gofmt/go vet clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…return

BREAKING API CHANGE: both readers now accept caller-owned channels and return an
error instead of returning a channel; they run synchronously (no internal goroutine)
and never close the channels — the caller owns concurrency, error handling, and
channel lifecycle.

- FindReader(ctx, re, maxMatchLength, reader, matches chan<- string) error
- FindReaderIndex(ctx, re, maxMatchLength, reader, matches chan<- string, indexes chan<- []int) error
- Return scanner.Err() at EOF so reader failures surface instead of looking like a
  clean EOF; return ctx.Err() on cancellation.
- FindReaderIndex still emits each index just before its match; document that the
  caller must drain both channels (buffer indexes by 1) or it deadlocks.
- Update both example tests, unit tests, and README to the new style.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vertoforce
vertoforce merged commit 2e1dcb6 into master Jul 16, 2026
vertoforce pushed a commit that referenced this pull request Oct 24, 2026
Redesign readers to caller-owned channels + error return
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.

1 participant