Created
July 12, 2020 03:43
-
-
Save dipeshdulal/23e590523d3b08438b4c0bf5a054aca4 to your computer and use it in GitHub Desktop.
Join Channel Client Side
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 joinChannel(ctx context.Context, client chatpb.ChatServiceClient) { | |
channel := chatpb.Channel{Name: *channelName, SendersName: *senderName} | |
stream, err := client.JoinChannel(ctx, &channel) | |
if err != nil { | |
log.Fatalf("client.JoinChannel(ctx, &channel) throws: %v", err) | |
} | |
fmt.Printf("Joined channel: %v \n", *channelName) | |
waitc := make(chan struct{}) | |
go func() { | |
for { | |
in, err := stream.Recv() | |
if err == io.EOF { | |
close(waitc) | |
return | |
} | |
if err != nil { | |
log.Fatalf("Failed to receive message from channel joining. \nErr: %v", err) | |
} | |
if *senderName != in.Sender { | |
fmt.Printf("MESSAGE: (%v) -> %v \n", in.Sender, in.Message) | |
} | |
} | |
}() | |
<-waitc | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment