Repository navigation
Split channel into sender/receiver - #88
Open
arnetheduck wants to merge 2 commits into
Open
arnetheduck wants to merge 2 commits into
arnetheduck wants to merge 2 commits into
Conversation
Member
|
I need to fix the CI first, seems ready to go otherwise. |
Author
arnetheduck
marked this pull request as draft
September 20, 2026 20:09
Author
|
#91 is blocking this for now |
By separating the handles responsible for the two sides of a channel, we get to support an intuitive api for closing channels that is safe by construction, ie there's no risk that senders write into a channel closed for sending and vice versa. Both receivers and senders can be copied and moved around so that they can each be shared by multiple threads. The principle of operation is simple: * senders and receivers have separate refcounts on the raw channel * with all senders gone, it means no more items will be pushed to the channel - all queued receivers are woken up and told it's over (once they've drained the channel) * with all receivers gone, it means no more messages can be pushed into the channel - we can free the buffer and sending becomes a no-op * with both gone, we release the channel resources. On the sending side, we return a `bool` for "no more receivers" - on the receiving side, we return `default(T)` or a `bool` for the var-taking version - both sides can check if the channel was closed to disambiguate.
arnetheduck
marked this pull request as ready for review
October 19, 2026 07:54
Author
|
So this is now minimally correct with respect to #91 at least, via a destructor call in the lock - not the best in terms of efficiency, but in line with other inefficiences already present (copying/destroying/etc inside the contended lock). |
This branch has not been deployed
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.
By separating the handles responsible for the two sides of a channel, we get to support an intuitive api for closing channels that is safe by construction, ie there's no risk that senders write into a channel closed for sending and vice versa.
Both receivers and senders can be copied and moved around so that they can each be shared by multiple threads.
The principle of operation is simple:
On the sending side, we return a
boolfor "no more receivers" - on the receiving side, we returndefault(T)or aboolfor the var-taking version - both sides can check if the channel was closed to disambiguate.