Skip to content

Instantly share code, notes, and snippets.

@iporsut
Created March 2, 2015 15:07
Show Gist options
  • Save iporsut/c1e5e62ad1d5411b7bf6 to your computer and use it in GitHub Desktop.
Save iporsut/c1e5e62ad1d5411b7bf6 to your computer and use it in GitHub Desktop.
Goroutine SecondCounter and FiveSecondCounter Channel Sync
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