From d845d6a26f0967506f6562e5de05a71e7e9f4d1a Mon Sep 17 00:00:00 2001 From: hannahhoward Date: Thu, 8 Nov 2018 13:49:54 -0800 Subject: [PATCH] Wait for all go routines to finish before function returns --- merkledag.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/merkledag.go b/merkledag.go index 8b522650f310..f2965ee6fae2 100644 --- a/merkledag.go +++ b/merkledag.go @@ -376,14 +376,16 @@ func EnumerateChildrenAsyncDepth(ctx context.Context, getLinks GetLinks, c cid.C done := make(chan struct{}) var setlk sync.Mutex + var wg sync.WaitGroup errChan := make(chan error) fetchersCtx, cancel := context.WithCancel(ctx) - + defer wg.Wait() defer cancel() - for i := 0; i < FetchGraphConcurrency; i++ { + wg.Add(1) go func() { + defer wg.Done() for cdepth := range feed { ci := cdepth.cid depth := cdepth.depth