This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Evar ( | |
concurrent = 5 | |
semaphoreChan = make(chan struct{}, concurrent) | |
) | |
func doWork(item int) { | |
semaphoreChan <- struct{}{} // block while full | |
go func() { | |
defer func() { | |
<-semaphoreChan // read to release a slot |