Sobes.tech
Junior — Senior

Sequence of output from goroutines

livecode

Task condition

What text will appear in the console and in what order will the output occur?

func main() {
  runtime.GOMAXPROCS(1)

  var wg sync.WaitGroup

  wg.Add(1)

  go func() {
    time.Sleep(time.Second * 2)
    fmt.Println("1")
    wg.Done()
  }()

  go func() {
    fmt.Println("2")
  }()

  wg.Wait()

  fmt.Println("3")
}