Created
March 2, 2015 15:07
-
-
Save iporsut/c1e5e62ad1d5411b7bf6 to your computer and use it in GitHub Desktop.
Goroutine SecondCounter and FiveSecondCounter Channel Sync
This file contains hidden or 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" | |
"time" | |
) | |
var oneDone chan bool = make(chan bool) | |
var fiveDone chan bool = make(chan bool) | |
func SecondCounter() { | |
for i := 1; i <= 20; i++ { | |
time.Sleep(1 * time.Second) | |
fmt.Println("Second ", i) | |
} | |
oneDone <- true | |
} | |
func FiveSecondCounter() { | |
for i := 1; i <= 4; i++ { | |
time.Sleep(5 * time.Second) | |
fmt.Println("FiveSecond ", i) | |
} | |
fiveDone <- true | |
} | |
func main() { | |
go SecondCounter() | |
go FiveSecondCounter() | |
<-oneDone | |
<-fiveDone | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment