Buffered channels
The topic of this subsection is buffered channels. These are channels that allow the Go scheduler to put jobs in the queue quickly in order to be able to deal with more requests.
Moreover, you can use buffered channels as semaphores in order to limit the throughput of your application.
The technique presented here works as follows: all incoming requests are forwarded to a channel, which processes them one by one. When the channel is done processing a request, it sends a message to the original caller saying that it is ready to process a new one. So, the capacity of the buffer of the channel restricts the number of simultaneous requests that it can keep.
The technique will be presented with the help of the code found in ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access