Created
July 12, 2020 03:04
-
-
Save dipeshdulal/e10c2b8d39e0871149bc5cba0c35007a to your computer and use it in GitHub Desktop.
JoinChannel Implementation for Chat Server
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
func (s *chatServiceServer) JoinChannel(ch *chatpb.Channel, msgStream chatpb.ChatService_JoinChannelServer) error { | |
msgChannel := make(chan *chatpb.Message) | |
s.channel[ch.Name] = append(s.channel[ch.Name], msgChannel) | |
// doing this never closes the stream | |
for { | |
select { | |
case <-msgStream.Context().Done(): | |
return nil | |
case msg := <-msgChannel: | |
fmt.Printf("GO ROUTINE (got message): %v \n", msg) | |
msgStream.Send(msg) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment