refactor: 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 4537803f52

View file

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