evdist: Publish next settings change

This commit is contained in:
nemunaire 2024-03-17 16:49:15 +01:00
commit 0db9e9b539
5 changed files with 76 additions and 21 deletions

View file

@ -37,7 +37,7 @@ func (l *distList) TimerNextEvent() *time.Timer {
return time.NewTimer(time.Until(*min))
}
func (l *distList) AddEvent(nsf DistEvent) {
func (l *distList) AddEvent(nsf DistEvent, firstItemChanged func(DistEvent)) {
l.Lock.Lock()
istop := len(l.List)
@ -59,10 +59,13 @@ func (l *distList) AddEvent(nsf DistEvent) {
if istop == 0 {
l.ResetTimer()
if firstItemChanged != nil {
firstItemChanged(nsf)
}
}
}
func (l *distList) DelEvent(id int64) {
func (l *distList) DelEvent(id int64, firstItemChanged func(DistEvent)) {
l.Lock.Lock()
istop := len(l.List)
@ -83,6 +86,13 @@ func (l *distList) DelEvent(id int64) {
if istop == 0 {
l.ResetTimer()
if firstItemChanged != nil {
if len(l.List) == 0 {
firstItemChanged(nil)
} else {
firstItemChanged(l.List[0])
}
}
}
}