From 787078f7202836c68a5aea6a0f506bc24f3c9380 Mon Sep 17 00:00:00 2001 From: tyler Date: Wed, 31 Jan 2024 11:23:32 -0500 Subject: [PATCH] Added checks for nil values in chat client StopChatStream function --- chat.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/chat.go b/chat.go index c25e54a..a1dd3bf 100644 --- a/chat.go +++ b/chat.go @@ -276,9 +276,18 @@ func (c *Client) StartChatStream(handle func(cv ChatView), handleError func(err func (c *Client) StopChatStream() { c.chatStreamMu.Lock() defer c.chatStreamMu.Unlock() + + if c.chatStream == nil { + return + } // TODO: what order should these be in? - c.chatStream.sseClient.Unsubscribe(c.chatStream.sseEvent) - c.chatStream.stop() + if c.chatStream.sseClient != nil { + c.chatStream.sseClient.Unsubscribe(c.chatStream.sseEvent) + } + if c.chatStream.stop != nil { + c.chatStream.stop() + } + c.chatStream = nil }