...

/

Puzzle 8 Explanation: Closure

Puzzle 8 Explanation: Closure

Understand how wait() works in Go.

We'll cover the following...

Try it yourself

Try running the code below to see the result for yourself.

Press + to interact
package main
import (
"fmt"
"sync"
"time"
)
func main() {
var wg sync.WaitGroup
for _, n := range []int{3, 1, 2} {
wg.Add(1)
go func() {
defer wg.Done()
time.Sleep(time.Duration(n) * time.Millisecond)
fmt.Printf("%d ", n)
}()
}
wg.Wait()
fmt.Println()
}

Explanation

...
Access this course and 1400+ top-rated courses and projects.