Remix.run Logo
stefanos82 2 days ago

Can you provide an example please?

listeria 2 days ago | parent [-]

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 2 days ago | parent [-]

This is really amazing, thank you so much!

listeria 2 days ago | parent [-]

It's called struct embedding, there an article about it in Go by Example if you're interested: https://gobyexample.com/struct-embedding

stefanos82 2 days ago | parent [-]

Thank you @listeria, today I learned about struct embedding lol!

genghisjahn 2 days ago | parent [-]

I rediscover this about once a year and am always so happy when I do.