Created
November 1, 2024 11:32
-
-
Save Abdulsametileri/2b2a142f1ff9d85e31b07598ecf6dcf3 to your computer and use it in GitHub Desktop.
workerpoolpattern-in.go
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
package processor | |
import "sync" | |
type workerPool struct { | |
limit chan struct{} | |
wg sync.WaitGroup | |
} | |
func (l *workerPool) acquire() { | |
l.wg.Add(1) | |
l.limit <- struct{}{} | |
} | |
func (l *workerPool) wait() { | |
l.wg.Wait() | |
} | |
func (l *workerPool) release() { | |
<-l.limit | |
l.wg.Done() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment