Created
February 28, 2016 16:23
-
-
Save gerep/8b8669f8ed942d9dd343 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" | |
"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) | |
} | |
} |
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 | |
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