Correctly handle reading from events channel
@@ -42,18 +42,15 @@ var Command = cli.Command{
defer cancel()
eventsClient := client.EventService()
eventsCh, errCh := eventsClient.Subscribe(ctx, context.Args()...)
- for {
+ open := true
+ for open {
var e *events.Envelope
select {
- case evt, closed := <-eventsCh:
- if closed {
- return nil
- }
- e = evt
- case err := <-errCh:
+ case e = <-eventsCh:
+ case err, open = <-errCh:
return err
}
-
+ if e != nil {
var out []byte
if e.Event != nil {
v, err := typeurl.UnmarshalAny(e.Event)
@@ -65,7 +62,6 @@ var Command = cli.Command{
return err
}
}
-
if _, err := fmt.Println(
e.Timestamp,
e.Namespace,
@@ -75,5 +71,7 @@ var Command = cli.Command{
return err
}
}
+ }
+ return nil
},
}
