Skip to main content

Concurrency In Golang

In this series, we will be discussing Concurrency and its patterns in golang

📄️ WaitGroups

In the previous article, Introduction to Concurrency in Golang, of the series,Concurrency in Golang, we came across a problem where one or more goroutines might not necessarily finish execution before the main goroutine does, thus we were unable to see the message printed by the unfinished goroutine. We fixed the issue by adding time.Sleep() in the main goroutine to put it to sleep for a few seconds and thus increasing the probability of other goroutines finishing before the main does. Although our code worked in that particular case, most certainly it will not work for all cases. In this article, we will see, how we can make use of the WaitGroup synchronization primitive provided by Go.