Skip to content

Instantly share code, notes, and snippets.

@xfstart07
Last active May 5, 2023 09:37
Show Gist options
  • Select an option

  • Save xfstart07/8a84b91ae070143c71693be9501655ad to your computer and use it in GitHub Desktop.

Select an option

Save xfstart07/8a84b91ae070143c71693be9501655ad to your computer and use it in GitHub Desktop.
waitgroup control #go
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