Рет қаралды 7,730
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.
Buffered Channels in Go - tour.golang.or...
Semaphore package - pkg.go.dev/gol...
Source Code (with golang.org/x/sync/semaphore) - play.golang.or...
Source Code (with buffered channel) - play.golang.or...
💼 Golang Cafe - golang.cafe
📬 Golang Cafe Jobs Newsletter - golang.cafe/ne...
🐦 Golang Cafe Twitter - / golangcafe
📣 Telegram Channel - t.me/golangcafe
🙏 Found this video useful? Help me make more by donating $5.00 - golang.cafe/5USD