refactor(moq-net): make request_broadcast/subscribe/fetch_group infallible#1890
Merged
Conversation
5132ce1 to
1128ecd
Compare
…lible
These three consumer-side lookups each returned `Result<kio::Pending<..>>`:
a synchronous Result wrapping a future that itself resolves to a Result. That
forced every caller into a double-unwrap (`x()?.await?`) or, when the synchronous
error had to be translated rather than propagated, the `async { x()?.await }.await`
dance. The synchronous error was never useful on its own: callers await the
result anyway, and even the one register-then-select caller (libmoq) just `?`s it.
Collapse all three to return a bare `kio::Pending<..>` and bake the former
synchronous errors into the future:
- `OriginConsumer::request_broadcast`: new internal `Requested::Failed(Error)`
variant carries `Unroutable`/`Dropped`.
- `TrackConsumer::subscribe`: the closed-track error already surfaces via
`TrackSubscribe::poll_ok`, so registration just skips when the track is closed.
- `TrackConsumer::fetch_group`: `TrackFetch::poll` already reports `NotFound`/abort,
so the synchronous `poll_fetch` check was a pure duplicate; it now only decides
whether to queue a request.
Call sites across moq-net, moq-relay, moq-rtc, moq-ffi, libmoq, moq-mux,
moq-audio, moq-boy, moq-gst, moq-bench, moq-native, and hang collapse from
`?.await?` to `.await?` (and tests from `.unwrap().await` to `.await`). The
remaining `broadcast.track(name)?` stays a plain `?`: it is a synchronous
accessor returning a handle, not a future, so a single `?` is idiomatic.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1128ecd to
3cc8d5f
Compare
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
Three consumer-side lookups in
rs/moq-neteach returnedResult<kio::Pending<…>>— a synchronousResultwrapping a future that itself resolves to aResult. That double layer forced every caller into eitherx()?.await?or, when the synchronous error had to be translated into a wire/HTTP response rather than propagated, the awkwardasync { x()?.await }.awaitdance:The synchronous error was never useful on its own: callers await the result anyway, and even the one register-then-
select!caller (libmoq) just?s it. So this collapses all three to return a barekio::Pending<…>and bakes the former synchronous errors into the future, resolved on.awaitlike every other outcome:OriginConsumer::request_broadcast— new internalRequested::Failed(Error)variant carriesUnroutable/Dropped.TrackConsumer::subscribe— the closed-track error already surfaces viaTrackSubscribe::poll_ok, so registration simply skips when the track is closed.TrackConsumer::fetch_group—TrackFetch::pollalready reportsNotFound/ abort, so the synchronouspoll_fetchcheck was a pure duplicate; it now only decides whether to queue a request.TrackConsumer::info()already worked this way, so this just makes the set consistent.The gross call sites become a single
.await:Public API changes (breaking)
In
rs/moq-net:OriginConsumer::request_broadcast→kio::Pending<BroadcastRequested>(wasResult<…, Error>)TrackConsumer::subscribe→kio::Pending<TrackSubscribe>(wasResult<…>)TrackConsumer::fetch_group→kio::Pending<TrackFetch>(wasResult<…>)These are breaking, hence the dev base per the branch-targeting rules.
The remaining
broadcast.track(name)?stays a plain?— it is a synchronous accessor returning a handle, not a future-in-a-Result, so a single?is idiomatic and not the wart being removed. The few survivingasync { … }blocks (ietf publisher, relayserve_fetch) are now justified: they flatten a genuinetrack()?lookup plus a separate.await, not one call's double-Result.Call-site sweep
Mechanical
?.await?→.await?(and tests.unwrap().await→.await) across: moq-net, moq-relay, moq-rtc, moq-ffi, libmoq, moq-mux, moq-audio, moq-boy, moq-gst, moq-bench, moq-native, hang.Cross-package sync
js/netmirrors thers/moq-netconsumer surface (requestBroadcast/subscribe/fetchGroup). Not updated in this PR — flagging for a follow-up so the JS side can decide whether to reshape to match.Test plan
cargo check --workspace --all-targetscleancargo test -p moq-net— 389 passedcargo test -p moq-mux -p moq-relay --lib— greenjust fixagainst the pinned nix toolchain before merge — this branch was formatted with the systemcargo fmtbecausenix developcouldn't allocate a pty in the dev environment.(Written by Claude)