Enhance map update handling and connection stability
- Introduced mechanisms to detect stale connections in the map updates, allowing for automatic reconnection if no messages are received within a specified timeframe. - Updated the `refresh` method in `SmartTileLayer` to return a boolean indicating whether the tile was refreshed, improving the handling of tile updates. - Enhanced the `Send` method in the `Topic` struct to drop messages for full subscribers while keeping them subscribed, ensuring continuous delivery of future updates. - Added a keepalive mechanism in the `WatchGridUpdates` handler to maintain the connection and prevent timeouts.
This commit is contained in:
@@ -15,7 +15,9 @@ func (t *Topic[T]) Watch(c chan *T) {
|
||||
t.c = append(t.c, c)
|
||||
}
|
||||
|
||||
// Send broadcasts to all subscribers.
|
||||
// Send broadcasts to all subscribers. If a subscriber's channel is full,
|
||||
// the message is dropped for that subscriber only; the subscriber is not
|
||||
// removed, so the connection stays alive and later updates are still delivered.
|
||||
func (t *Topic[T]) Send(b *T) {
|
||||
t.mu.Lock()
|
||||
defer t.mu.Unlock()
|
||||
@@ -23,9 +25,7 @@ func (t *Topic[T]) Send(b *T) {
|
||||
select {
|
||||
case t.c[i] <- b:
|
||||
default:
|
||||
close(t.c[i])
|
||||
t.c[i] = t.c[len(t.c)-1]
|
||||
t.c = t.c[:len(t.c)-1]
|
||||
// Channel full: drop this message for this subscriber, keep them subscribed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user