From a737e900279642b685913cd64f98ddd9f7678f5f Mon Sep 17 00:00:00 2001 From: Oktay Dinler Date: Fri, 14 Feb 2020 11:39:30 +0100 Subject: [PATCH] Fix logging interference with worker and main thread --- project.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/project.go b/project.go index 8bd7099..5f12c0f 100644 --- a/project.go +++ b/project.go @@ -204,6 +204,19 @@ func (project Project) WalkTodosOfDir(dirpath string) (<-chan TodoResult, contex output := make(chan TodoResult) var workers sync.WaitGroup + print := make(chan string) + go func() { + for { + select { + case <-ctx.Done(): + close(print) + return + case v := <-print: + defer fmt.Println(v) + } + } + }() + for i := 0; i < runtime.NumCPU(); i++ { workers.Add(1) go func() { @@ -219,7 +232,7 @@ func (project Project) WalkTodosOfDir(dirpath string) (<-chan TodoResult, contex } if stat.IsDir() { // FIXME(#145): snitch should go inside of git submodules recursively - fmt.Printf("[WARN] `%s` is probably a submodule. Skipping it for now...\n", filepath) + print <- fmt.Sprintf("[WARN] `%s` is probably a submodule. Skipping it for now...", filepath) continue }