refactor start method

This commit is contained in:
Dominic Breuker
2018-03-12 08:54:36 +01:00
parent f0474514f0
commit 10bd34b447

View File

@@ -37,13 +37,13 @@ func Start(cfg *config.Config, b *Bindings, sigCh chan os.Signal) chan struct{}
psEventCh := startPSS(b.PSS, b.Logger, triggerCh)
go func() {
for {
<-time.After(100 * time.Millisecond)
triggerCh <- struct{}{}
}
}()
triggerEvery(100*time.Millisecond, triggerCh)
exit := printOutput(cfg, b, sigCh, fsEventCh, psEventCh)
return exit
}
func printOutput(cfg *config.Config, b *Bindings, sigCh chan os.Signal, fsEventCh chan string, psEventCh chan string) chan struct{} {
exit := make(chan struct{})
go func() {
for {
@@ -94,6 +94,15 @@ func startPSS(pss PSScanner, logger Logger, triggerCh chan struct{}) (psEventCh
return psEventCh
}
func triggerEvery(d time.Duration, triggerCh chan struct{}) {
go func() {
for {
<-time.After(d)
triggerCh <- struct{}{}
}
}()
}
func logErrors(errCh chan error, logger Logger) {
for {
err := <-errCh