raidcheck/filter_changed_states.go
2021-12-22 22:17:51 +01:00

33 lines
631 B
Go

package main
import (
"reflect"
"git.tordarus.net/Tordarus/dockerhealth"
)
func filterChanges(in <-chan RaidState) <-chan RaidState {
out := make(chan RaidState, 4)
go func(in <-chan RaidState, out chan<- RaidState) {
defer close(out)
currentStates := map[string]RaidState{}
first := true
for state := range in {
if oldState, ok := currentStates[state.Name]; !ok || !reflect.DeepEqual(oldState.DevicesUp, state.DevicesUp) {
dockerhealth.Healthy = first
currentStates[state.Name] = state
out <- state
} else {
dockerhealth.Healthy = true
}
first = false
}
}(in, out)
return out
}