Skip to content

Instantly share code, notes, and snippets.

@drtaka
Created January 31, 2020 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drtaka/8e29e335b5832e11da2803647f7c8660 to your computer and use it in GitHub Desktop.
Save drtaka/8e29e335b5832e11da2803647f7c8660 to your computer and use it in GitHub Desktop.
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