mirror of
https://github.com/DominicBreuker/pspy.git
synced 2025-12-21 11:44:51 +00:00
refactor start method
This commit is contained in:
@@ -37,13 +37,13 @@ func Start(cfg *config.Config, b *Bindings, sigCh chan os.Signal) chan struct{}
|
|||||||
|
|
||||||
psEventCh := startPSS(b.PSS, b.Logger, triggerCh)
|
psEventCh := startPSS(b.PSS, b.Logger, triggerCh)
|
||||||
|
|
||||||
go func() {
|
triggerEvery(100*time.Millisecond, triggerCh)
|
||||||
for {
|
|
||||||
<-time.After(100 * time.Millisecond)
|
|
||||||
triggerCh <- struct{}{}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
|
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{})
|
exit := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
@@ -94,6 +94,15 @@ func startPSS(pss PSScanner, logger Logger, triggerCh chan struct{}) (psEventCh
|
|||||||
return 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) {
|
func logErrors(errCh chan error, logger Logger) {
|
||||||
for {
|
for {
|
||||||
err := <-errCh
|
err := <-errCh
|
||||||
|
|||||||
Reference in New Issue
Block a user