<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>wait-group on Golang</title><link>https://golang.k5kc.com/tags/wait-group/</link><description>Recent content in wait-group on Golang</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Sun, 16 Aug 2020 00:13:00 +0530</lastBuildDate><atom:link href="https://golang.k5kc.com/tags/wait-group/index.xml" rel="self" type="application/rss+xml"/><item><title>Wait for goroutines Using WaitGroups</title><link>https://golang.k5kc.com/2020/08/16/4.wait-groups/</link><pubDate>Sun, 16 Aug 2020 00:13:00 +0530</pubDate><guid>https://golang.k5kc.com/2020/08/16/4.wait-groups/</guid><description>Syntax A sync.WaitGroup waits for a group of goroutines to finish.
var wg sync.WaitGroup wg.Add(2) go func() { // Do work wg.Done() }() go func() { // Do work wg.Done() }() wg.Wait() First the main goroutine calls Add to set the number of goroutines to wait for. Then two new goroutines run and call Done when finished. At the same time, Wait is used to block until these two goroutines have finished.</description></item></channel></rss>