Skip to content

Instantly share code, notes, and snippets.

@orian

orian/example.go

Created Jul 25, 2017
Embed
What would you like to do?
func (p *XImpl) Listen(_ *empty.Empty, rec services.X_ListenServer) error {
c := make(chan *services.X, 16)
p.add(c)
defer p.remove(c)
ctx := rec.Context()
for {
select {
case v := <-c:
if err := rec.Send(v); err != nil {
return err
}
case <-ctx.Done():
return nil
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment