Skip to content

Instantly share code, notes, and snippets.

@gerep
Created February 28, 2016 16:23
Show Gist options
  • Save gerep/8b8669f8ed942d9dd343 to your computer and use it in GitHub Desktop.
Save gerep/8b8669f8ed942d9dd343 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
)
func main() {
message := make(chan string, 2) // buffer
count := 3
go func() {
for i := 1; i <= count; i++ {
fmt.Println("send message")
message <- fmt.Sprintf("message %d", i)
}
}()
time.Sleep(time.Second * 3)
for i := 1; i <= count; i++ {
fmt.Println(<-message)
}
}
package main
func main() {
done := make(chan bool)
go func() {
println("goroutine message")
done <- true
}()
println("main funcion message")
<-done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment