Created
July 25, 2017 14:41
-
-
Save orian/85f4f2a07deaafeba3000841b9d5fa61 to your computer and use it in GitHub Desktop.
This file contains 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 (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