diff --git a/subscribe.go b/subscribe.go index 334aca4..4d31478 100644 --- a/subscribe.go +++ b/subscribe.go @@ -69,26 +69,30 @@ func parseEvents(ctx context.Context, conn net.Conn) (<-chan Event, error) { go func() { defer conn.Close() + <-ctx.Done() + }() + + go func() { defer close(out) for ctx.Err() == nil { if _, err := conn.Read(make([]byte, 6)); err != nil { - panic(err) // TODO debug flag with error printing + return } var length uint32 if err := binary.Read(conn, binary.LittleEndian, &length); err != nil { - panic(err) // TODO debug flag with error printing + return } var messageType EventType if err := binary.Read(conn, binary.LittleEndian, &messageType); err != nil { - panic(err) // TODO debug flag with error printing + return } event, err := parseEvent(conn, length, messageType) if err != nil { - panic(err) // TODO debug flag with error printing + return } out <- event