Created
June 13, 2013 08:21
-
-
Save jney/5772081 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 ( | |
"fmt" | |
"sync" | |
"time" | |
) | |
func main() { | |
var wg sync.WaitGroup | |
wg.Add(1) | |
go say("3 seconds", 3*time.Second, &wg) | |
wg.Add(1) | |
go say("2 seconds", 2*time.Second, &wg) | |
wg.Add(1) | |
go say("1 seconds", 1*time.Second, &wg) | |
wg.Wait() | |
} | |
func say(text string, duration time.Duration, wg *sync.WaitGroup) { | |
time.Sleep(duration) | |
fmt.Println(text) | |
wg.Done() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment