Created
January 31, 2020 04:51
-
-
Save drtaka/8e29e335b5832e11da2803647f7c8660 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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