From aedc41a0215127da16d41ef511c17b7beacd829b Mon Sep 17 00:00:00 2001 From: Nick Dumas Date: Mon, 1 May 2023 16:59:45 -0400 Subject: [PATCH] Proper synchronization. --- cmd/fsm_demo/main.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/fsm_demo/main.go b/cmd/fsm_demo/main.go index 21e7e23..9e7be51 100644 --- a/cmd/fsm_demo/main.go +++ b/cmd/fsm_demo/main.go @@ -6,6 +6,7 @@ import ( "io/fs" "os" "strings" + "sync" "go.uber.org/zap" @@ -42,7 +43,10 @@ func main() { return nil } + var wg sync.WaitGroup go func() { + defer wg.Done() + wg.Add(1) for fn := range fileNames { if !strings.HasSuffix(fn, ".md") { continue @@ -61,5 +65,7 @@ func main() { if err != nil { l.Fatal("error walking for files", zap.Error(err)) } + close(fileNames) + wg.Wait() }