use context to stop main() jobs

use
This commit is contained in:
sentriz
2024-02-27 00:33:39 +00:00
parent a66463a68c
commit 02606087dc
6 changed files with 24 additions and 50 deletions

View File

@@ -2,6 +2,7 @@
package scanner
import (
"context"
"errors"
"fmt"
"io/fs"
@@ -111,7 +112,7 @@ func (s *Scanner) ScanAndClean(opts ScanOptions) (*State, error) {
return st, errors.Join(st.errs...)
}
func (s *Scanner) ExecuteWatch(done <-chan struct{}) error {
func (s *Scanner) ExecuteWatch(ctx context.Context) error {
watcher, err := fsnotify.NewWatcher()
if err != nil {
return fmt.Errorf("creating watcher: %w", err)
@@ -180,7 +181,7 @@ func (s *Scanner) ExecuteWatch(done <-chan struct{}) error {
case err := <-watcher.Errors:
log.Printf("error from watcher: %v\n", err)
case <-done:
case <-ctx.Done():
return nil
}
}