Skip to content

Instantly share code, notes, and snippets.

@orian
Created July 25, 2017 14:41
Show Gist options
  • Save orian/85f4f2a07deaafeba3000841b9d5fa61 to your computer and use it in GitHub Desktop.
Save orian/85f4f2a07deaafeba3000841b9d5fa61 to your computer and use it in GitHub Desktop.
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