diff --git a/pkg/resource/files.go b/pkg/resource/files.go index df55183..dbe506a 100644 --- a/pkg/resource/files.go +++ b/pkg/resource/files.go @@ -43,21 +43,18 @@ func isIgnored(path string, ignoreFilePatterns []string) (bool, error) { func FromFiles(ctx context.Context, ignoreFilePatterns []string, paths ...string) (<-chan Resource, <-chan error) { resources := make(chan Resource) errors := make(chan error) - stop := false - - go func() { - <-ctx.Done() - stop = true - }() go func() { for _, path := range paths { // we handle errors in the walk function directly // so it should be safe to discard the outer error err := filepath.Walk(path, func(p string, i os.FileInfo, err error) error { - if stop == true { + select { + case <-ctx.Done(): return io.EOF + default: } + if err != nil { return err } diff --git a/pkg/resource/stream.go b/pkg/resource/stream.go index ca50f80..6b49b84 100644 --- a/pkg/resource/stream.go +++ b/pkg/resource/stream.go @@ -42,20 +42,17 @@ func SplitYAMLDocument(data []byte, atEOF bool) (advance int, token []byte, err func FromStream(ctx context.Context, path string, r io.Reader) (<-chan Resource, <-chan error) { resources := make(chan Resource) errors := make(chan error) - stop := false - - go func() { - <-ctx.Done() - stop = true - }() go func() { scanner := bufio.NewScanner(r) scanner.Split(SplitYAMLDocument) + SCAN: for res := scanner.Scan(); res != false; res = scanner.Scan() { - if stop == true { - break + select { + case <-ctx.Done(): + break SCAN + default: } resources <- Resource{Path: path, Bytes: scanner.Bytes()} }