fix: remove unused variable prevMessage

- update logic to send current serverMessage instead of prevMessage
- simplify message processing for improved clarity

🤖
This commit is contained in:
Sebastian Mark 2024-11-18 19:53:21 +01:00
parent 74ee5f3693
commit 46c3a4c0b1

View file

@ -14,7 +14,7 @@ var Done = make(chan struct{})
// Receives websocket messages and writes them to a channel.
// Closes the channel if websocket closes.
func (c *Client) ProcessServerMessages(channel chan<- GoTomato.ServerMessage) {
var serverMessage, prevMessage GoTomato.ServerMessage
var serverMessage GoTomato.ServerMessage
defer close(Done)
@ -30,7 +30,7 @@ func (c *Client) ProcessServerMessages(channel chan<- GoTomato.ServerMessage) {
c.LastErr = err
// Try to reconnect on unexpected disconnect
for {
channel <- prevMessage // send previous ServerMessage to update view
channel <- serverMessage // send last known ServerMessage to update view
time.Sleep(time.Second)
@ -50,6 +50,5 @@ func (c *Client) ProcessServerMessages(channel chan<- GoTomato.ServerMessage) {
c.LastErr = err
channel <- serverMessage
prevMessage = serverMessage
}
}