Last active
May 5, 2023 09:37
-
-
Save xfstart07/8a84b91ae070143c71693be9501655ad to your computer and use it in GitHub Desktop.
waitgroup control #go
This file contains hidden or 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 concurr | |
| import "sync" | |
| type routineGroup struct { | |
| waitGroup sync.WaitGroup | |
| } | |
| func newRoutineGroup() *routineGroup { | |
| return new(routineGroup) | |
| } | |
| func (g *routineGroup) Run(fn func()) { | |
| g.waitGroup.Add(1) | |
| go func() { | |
| defer g.waitGroup.Done() | |
| fn() | |
| }() | |
| } | |
| func (g *routineGroup) Wait() { | |
| g.waitGroup.Wait() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment