fixed context usage in Subscribe

This commit is contained in:
milarin 2024-02-14 15:26:17 +01:00
parent f2690ddf0b
commit 305cc6ce13

View File

@ -69,26 +69,30 @@ func parseEvents(ctx context.Context, conn net.Conn) (<-chan Event, error) {
go func() { go func() {
defer conn.Close() defer conn.Close()
<-ctx.Done()
}()
go func() {
defer close(out) defer close(out)
for ctx.Err() == nil { for ctx.Err() == nil {
if _, err := conn.Read(make([]byte, 6)); err != nil { if _, err := conn.Read(make([]byte, 6)); err != nil {
panic(err) // TODO debug flag with error printing return
} }
var length uint32 var length uint32
if err := binary.Read(conn, binary.LittleEndian, &length); err != nil { if err := binary.Read(conn, binary.LittleEndian, &length); err != nil {
panic(err) // TODO debug flag with error printing return
} }
var messageType EventType var messageType EventType
if err := binary.Read(conn, binary.LittleEndian, &messageType); err != nil { 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) event, err := parseEvent(conn, length, messageType)
if err != nil { if err != nil {
panic(err) // TODO debug flag with error printing return
} }
out <- event out <- event