diff --git a/main.go b/main.go index 60f4540..392c70b 100644 --- a/main.go +++ b/main.go @@ -151,8 +151,10 @@ func main() { tgSenderWorker(tgEvents, &wg, sleeper, log.New(os.Stderr, "TgSender", log.Lmicroseconds)), tgSender, &wg, log.New(os.Stderr, "SendToTg", log.Lmicroseconds))) + go CloseSatelOnCtrlC(s) + for e := range FilterByIndex(FilterByType( - FilterByLastSeen(CloseChanOnCtrlC(s.Events), "hs_wro_last_seen.bin", log.New(os.Stderr, "FilterByLastSeen", log.Lmicroseconds)), + FilterByLastSeen(s.Events, "hs_wro_last_seen.bin", log.New(os.Stderr, "FilterByLastSeen", log.Lmicroseconds)), allowedTypes), allowedIndexes) { logger.Print("Received change from SATEL: ", e) diff --git a/satel_utils.go b/satel_utils.go index 4a17c4b..1183d1f 100644 --- a/satel_utils.go +++ b/satel_utils.go @@ -93,26 +93,11 @@ var SATEL_STRING_TO_CHANGE_TYPE = map[string]satel.ChangeType{ "zone-isolate": satel.ZoneIsolate, } -func CloseChanOnCtrlC(ev <-chan satel.Event) <-chan satel.Event { - returnChan := make(chan satel.Event) +func CloseSatelOnCtrlC(s *satel.Satel) { exitSignal := make(chan os.Signal, 1) signal.Notify(exitSignal, os.Interrupt) - go func() { - defer close(returnChan) - loop: - for { - select { - case <-exitSignal: - return - case e, ok := <-ev: - if !ok { - break loop - } - returnChan <- e - } - } - }() - return returnChan + <-exitSignal + s.Close() } func StringToSatelChangeType(s string) (satel.ChangeType, error) {