Semaphores are another method for controlling how goroutines execute parallel tasks. Semaphores are convenient because they give us the ability to use a worker pool pattern, but we don't need to shut down workers after the work has been completed and the workers are idle. The idea of having a weighted semaphore in the Go language is relatively new; the sync package implementation of semaphores was implemented in early 2017, so it is one of the newest parallel task constructs.
If we take the example of a simple loop in the following code block, add 100 ms of latency to a request, and add an item to an array, we can quickly see that the amount of time it takes increases as these tasks are operating in a series:
package main
import (
"fmt"
"time"
)
func main() {
var out = make([]string, 5) ...