1
0
Fork 0

Log Satel disconnections

This commit is contained in:
Michał Rudowicz 2024-03-03 12:59:02 +01:00
parent 0cb91aed62
commit 765a41f8a1
2 changed files with 17 additions and 1 deletions

View File

@ -79,3 +79,17 @@ func FilterByLastSeen(ev <-chan satel.Event, dataStore *DataStore, logger *log.L
return returnChan
}
func CallWhenClosed(ev <-chan satel.Event, cbk func()) <-chan satel.Event {
returnChan := make(chan satel.Event)
go func() {
for e := range ev {
returnChan <- e
}
cbk()
close(returnChan)
}()
return returnChan
}

View File

@ -147,7 +147,9 @@ func main() {
go CloseSatelOnCtrlC(s)
for e := range FilterByIndex(FilterByType(
FilterByLastSeen(s.Events, &dataStore, log.New(os.Stderr, "FilterByLastSeen", log.Lmicroseconds)),
FilterByLastSeen(
CallWhenClosed(s.Events, func() { logger.Print("Satel disconnected.") }),
&dataStore, log.New(os.Stderr, "FilterByLastSeen", log.Lmicroseconds)),
allowedTypes),
allowedIndexes) {
logger.Print("Received change from SATEL: ", e)