feat(client): add Channel::shutdown() to terminate the task explicitly - #194
Open
mdmzfzl wants to merge 2 commits into
Open
feat(client): add Channel::shutdown() to terminate the task explicitly#194mdmzfzl wants to merge 2 commits into
mdmzfzl wants to merge 2 commits into
Conversation
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.
Problem
The client task completes only when every
Channelclone has been dropped:Receiver::recv()returnsNoneonce the last sender goes away, which becomesSessionError::Shutdown.That makes termination depend on how many handles exist and where they are held.
A caller that publishes a
Channelsomewhere outliving the task — a serviceregistry, a shared cache, anything with process lifetime — can never terminate
it, and awaiting the task's
JoinHandlehangs.Dropping handles in the right order is a convention every holder has to honour,
and nothing in the type system enforces it.
Change
Adds
Channel::shutdown(), which sends shutdown as a command rather thansignalling it by releasing the last handle:
Drop-based termination is unchanged, so this is additive — existing callers need
no changes.
Command gains a Shutdown variant, handled at both points where
reads its queue:
StateChange::Shutdown
Both already existed for the drop case, so this reuses the wind-down path rather
than adding a second one. Handling only the first would leave
solely while the device is reachable.
Semantics
processed — matching what dropping every handle does, since an
buffer before reporting closure.
within one response timeout of the last queued request.
completion.
harmless.
TCP and serial share ClientLoop, so both are covered with no
channel task.