Closed
Description
When I use errgroup.Group, I noticed I need much less code compared to sync.WaitGroup in certain situations. While keeping the existing methods of WaitGroup, can we add a Go(func())
function to make it more seamless? (And while at it, we could even make the Go
method return the WaitGroup
itself for chained calls? I wouldn't insist on this but it would be nice instead of it returning nothing)
It will be like:
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
defer wg.Done()
doWork()
}()
vs
wg := sync.WaitGroup{}.Go(func(){
doWork()
})
or potentially:
wg := sync.WaitGroup{}.Go(doWork)
I feel like it's not a crazy far-fetched idea since errgroup.Group already has this method.
And this would be a nice addition for semaphore.Weighted
as well, what do you think?