diff --git a/filters.go b/filters.go index 041615c..7f6bd6d 100644 --- a/filters.go +++ b/filters.go @@ -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 +} diff --git a/main.go b/main.go index b44ac84..0fd1757 100644 --- a/main.go +++ b/main.go @@ -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)