From 30a4cbfd963450637cd80f08b8c6b0a7c7ece92c Mon Sep 17 00:00:00 2001 From: Evgeny Kuznetsov Date: Tue, 28 Jan 2020 07:54:24 +0300 Subject: cleaner concurrency --- main.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index ba749c5..5a2bd3e 100644 --- a/main.go +++ b/main.go @@ -70,8 +70,7 @@ func main() { var wg sync.WaitGroup wg.Add(1) go describeFeed(feed, &wg) - wg.Add(len(feed.Items)) - go describeEpisodes(feed, &wg) + describeEpisodes(feed) feed.Created = time.Now() wg.Wait() @@ -161,10 +160,13 @@ func describeFeed(feed *feeds.Feed, wg *sync.WaitGroup) { feed.Description = string(re.ReplaceAll(programAbout, []byte(``))) } -func describeEpisodes(feed *feeds.Feed, wg *sync.WaitGroup) { +func describeEpisodes(feed *feeds.Feed) { + var wg sync.WaitGroup for _, item := range feed.Items { - go describeEpisode(item, wg) + wg.Add(1) + go describeEpisode(item, &wg) } + wg.Wait() } func describeEpisode(item *feeds.Item, wg *sync.WaitGroup) { -- cgit v1.2.3