generation-aware playback statuses
This commit is contained in:
@@ -3,8 +3,9 @@ package playback
|
||||
import "sync"
|
||||
|
||||
type StatusStore struct {
|
||||
mu sync.RWMutex
|
||||
statuses map[Unit]Status
|
||||
mu sync.RWMutex
|
||||
generation uint64
|
||||
statuses map[Unit]Status
|
||||
}
|
||||
|
||||
func NewStatusStore() *StatusStore {
|
||||
@@ -15,8 +16,15 @@ func NewStatusStore() *StatusStore {
|
||||
|
||||
func (s *StatusStore) Observe(status Status) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if status.Generation < s.generation {
|
||||
return
|
||||
}
|
||||
if status.Generation > s.generation {
|
||||
clear(s.statuses)
|
||||
s.generation = status.Generation
|
||||
}
|
||||
s.statuses[status.Unit] = status
|
||||
s.mu.Unlock()
|
||||
}
|
||||
|
||||
func (s *StatusStore) Snapshot(unit Unit) (Status, bool) {
|
||||
|
||||
Reference in New Issue
Block a user