Files
hnh-map/internal/app/topic.go
Nikolay Tatarinov 5ffa10f8b7 Update project structure and enhance frontend functionality
- Added a new AGENTS.md file to document the project structure and conventions.
- Updated .gitignore to include node_modules and refined cursor rules.
- Introduced new backend and frontend components for improved map interactions, including context menus and controls.
- Enhanced API composables for better admin and authentication functionalities.
- Refactored existing components for cleaner code and improved user experience.
- Updated README.md to clarify production asset serving and user setup instructions.
2026-02-25 16:32:55 +03:00

45 lines
774 B
Go

package app
import "sync"
// Topic is a generic pub/sub for broadcasting updates.
type Topic[T any] struct {
c []chan *T
mu sync.Mutex
}
// Watch subscribes a channel to receive updates.
func (t *Topic[T]) Watch(c chan *T) {
t.mu.Lock()
defer t.mu.Unlock()
t.c = append(t.c, c)
}
// Send broadcasts to all subscribers.
func (t *Topic[T]) Send(b *T) {
t.mu.Lock()
defer t.mu.Unlock()
for i := 0; i < len(t.c); i++ {
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]
}
}
}
// Close closes all subscriber channels.
func (t *Topic[T]) Close() {
for _, c := range t.c {
close(c)
}
t.c = t.c[:0]
}
type Merge struct {
From, To int
Shift Coord
}