From 10bd34b447a6e54bf9d4ef9a248481b6a2524f34 Mon Sep 17 00:00:00 2001 From: Dominic Breuker Date: Mon, 12 Mar 2018 08:54:36 +0100 Subject: [PATCH] refactor start method --- internal/pspy/pspy.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/internal/pspy/pspy.go b/internal/pspy/pspy.go index 0416efa..6c64aa8 100644 --- a/internal/pspy/pspy.go +++ b/internal/pspy/pspy.go @@ -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