-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Currently, there is only a single shared channel that all peers use. This channel is created by the conference and passed to each peer. Each peer gets a wrapped copy of the channel which adds the identifiers (the sender of the message) to each message. Then peers write to the channel and the conference listens on the channel to get peer updates.
This means that there is a custom-wrapped version of the channel that is actually never closed (it could get closed once the last peer ends, but by the receiver, not by the sender which is a bit odd and not particularly idiomatic in Go).
A much more idiomatic and elegant approach would be each peer creating its own channel to report the updates and returning the listening part to the caller. That way, when the peer feels like it's done and the channel is not required, the peer could close the channel. The caller will listen to the channel to get peer updates and get notified when the channel is closed. This means that the conference would either listen not on a single peer channel, but on a slice of channels (the size of each changes dynamically) and stop the conference once the last channel is closed. This would require the usage of reflect.Select() and dynamically managing the size of the channel, but would result in a more predictable and idiomatic API that is also easier to reason about.