5 ms·
something like this would do it: package main import ( "sync" "time" ) type WaitGroup struct { sync.WaitGroup } func (wg *Wait
by listeria 1y ago
something like this would do it:
package main
import (
"sync"
"time"
)
type WaitGroup struct {
sync.WaitGroup
}
func (wg *WaitGroup) Go(fn func()) {
wg.Add(1)
go func() {
defer wg.Done()
fn()
}()
}
func main() {
var wg WaitGroup
wg.Go(func() { time.Sleep(1 * time.Second) })
wg.Wait()
}
- stefanos82 1y agoThis is really amazing, thank you so much!
- listeria 1y agoIt's called struct embedding, there an article about it in Go by Example if you're interested: https://gobyexample.com/struct-embedding https://gobyexample.com/struct-embedding
- stefanos82 1y agoThank you @listeria, today I learned about struct embedding lol!
- genghisjahn 1y agoI rediscover this about once a year and am always so happy when I do.