Semaphores are a synchronization mechanism not new to computer science and present in other programming languages other than Go. With Semaphores we can synchronize access to multiple resources or in the episode we are going to see today, we are rate-limiting or throttling a set of concurrent workers to a pre-defined fixed capacity.
In this episode we are going to look at our we can limit the number of concurrent go routines running by using a buffered channel first and later on a packaged solution developed by the Go team (golang.org/x/sync/semaphore).
Buffered channels are the perfect solution for this problem as they are a tool to communicate safely between concurrent workers in go.
#golang #go #semaphore pattern