Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package main
import (
"sync"
"time"
"fmt"
)
/**
WaitGroup の使い方
*/
func main() {
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
fmt.Println("now 1st go func")
time.Sleep(1 * time.Second)
fmt.Println("now 1st go func done")
}()
wg.Add(1)
go func() {
defer wg.Done()
fmt.Println("now 2nd go func")
time.Sleep(3 * time.Second)
fmt.Println("now 2nd go func done")
}()
fmt.Println("befer wait")
wg.Wait()
fmt.Println("Done")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment