refactor(session): collapse the request openers into a generic helper#29
Merged
Conversation
Subscribe, Fetch, TrackStatus, PublishNamespace, SubscribeNamespace, and SubscribeTracks all repeated the same §10.1 skeleton: openAllocRequest → readResponse → switch on OK / REQUEST_ERROR / default → wrap. Fetch and TrackStatus even carried //nolint:dupl waivers for it. Extract awaitRequestResponse[OK, R], a generic primitive that owns the open / await-OK / error-mapping skeleton and delegates only the success case (OK type + handle construction) to a per-opener closure. The REQUEST_ERROR → *RequestRejectedError mapping and the "unexpected response" and "read X response" error strings now live in one place. The operation name in those errors is derived from m.Type() rather than a passed-in label. Net change removes both dupl waivers and ~150 lines of boilerplate; no behavior change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
577285c to
ba32e92
Compare
Publish shares the same open / await-OK / error-mapping skeleton as the other six openers; it differed only by pre-allocating its Track Alias before opening (and OpenPublish is just openAllocRequest, which the helper already calls). Route it through awaitRequestResponse too, keeping the pre-open alias allocation in Publish itself. No behavior change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
Publish,Subscribe,Fetch,TrackStatus,PublishNamespace,SubscribeNamespace, andSubscribeTracksall repeated the same §10.1 request skeleton:FetchandTrackStatuseven carried//nolint:duplwaivers acknowledging the duplication.This extracts a single generic primitive,
awaitRequestResponse[OK, R], inrequest.go. It owns the open / await-OK / error-mapping skeleton and delegates only the success case — the expectedOKmessage type and the typed-handle construction — to a per-opener closure:The
REQUEST_ERROR → *RequestRejectedErrormapping, theunexpected %s in X responseerror, and theread X responsewrapping now live in one place instead of seven. The operation name in those errors is derived fromm.Type()(which already stringifies toSUBSCRIBE,FETCH,TRACK_STATUS, …), so there is no redundant label to keep in sync.Publishkeeps its one distinguishing step — pre-allocating the Track Alias before the open — in the method body, then routes through the same helper (OpenPublishis justopenAllocRequest, which the helper already calls).Why
//nolint:duplwaivers — the duplication is gone, not suppressed.Behavior
No behavior change. The helper checks the
OKtype first, thenREQUEST_ERROR, then falls through to the unexpected-response error — identical ordering, outcomes, and error strings to the original type switches.OKis matched via a type assertion on the type parameter, which keys on the concrete wire type (*SubscribeOK,*FetchOK,*RequestOK; noteTrackStatusOK = RequestOK).Testing
go build ./...go test ./...(full suite)go test -race ./pkg/moqt/session/... ./pkg/relay/...golangci-lint run ./pkg/moqt/session/...— 0 issues🤖 Generated with Claude Code