From 305cc6ce13e3a0fe71e77b5f258e0839900affb7 Mon Sep 17 00:00:00 2001 From: milarin Date: Wed, 14 Feb 2024 15:26:17 +0100 Subject: [PATCH] fixed context usage in Subscribe --- subscribe.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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