Refactor reconnect #36

Closed
opened 2024-11-18 18:52:11 +00:00 by smark · 1 comment
Owner
			// Try to reconnect on unexpected disconnect
			for {
				channel <- prevMessage // send previous ServerMessage to update view

				time.Sleep(time.Second)

				// reconnect while preserving password
				pw := c.Password
				*c = Connect(c.Server)
				c.Password = pw

				if c.Connected() {
					break
				}
			}
			continue

prevMessage wird eigentlich nicht gebraucht und kann weg. serverMessage ist innerhalb des Loops immer die Message.

ChatGPT sagt, man könnte sowas machen:

func (c *Connect) reconnect() {
	for !c.Connected() {
		// send previous ServerMessage to update view
		channel <- serverMessage

		// wait for 1 second before attempting to reconnect
		<-time.After(time.Second)

		// reconnect to server
		pw := c.Password
		*c = Connect(c.Server)
		c.Password = pw
	}
}
```go // Try to reconnect on unexpected disconnect for { channel <- prevMessage // send previous ServerMessage to update view time.Sleep(time.Second) // reconnect while preserving password pw := c.Password *c = Connect(c.Server) c.Password = pw if c.Connected() { break } } continue ``` `prevMessage` wird eigentlich nicht gebraucht und kann weg. `serverMessage` ist innerhalb des Loops immer die Message. ChatGPT sagt, man könnte sowas machen: ```go func (c *Connect) reconnect() { for !c.Connected() { // send previous ServerMessage to update view channel <- serverMessage // wait for 1 second before attempting to reconnect <-time.After(time.Second) // reconnect to server pw := c.Password *c = Connect(c.Server) c.Password = pw } } ```
Author
Owner

closed by 342ecde

closed by 342ecde
smark closed this issue 2024-11-21 19:05:49 +00:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: pomodoro/ChronoTomato#36
No description provided.