Created
November 19, 2012 08:22
-
-
Save vderyagin/4109558 to your computer and use it in GitHub Desktop.
concurrent "Hello World" in Golang
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" | |
/* | |
concurrent hello world | |
*/ | |
func main() { | |
sayHello := make(chan bool) | |
sayWorld := make(chan bool) | |
finished := make(chan bool) | |
go func() { | |
<-sayWorld | |
fmt.Println("World") | |
finished <- true | |
}() | |
go func() { | |
<-sayHello | |
fmt.Print("Hello ") | |
sayWorld <- true | |
}() | |
sayHello <- true // kick off | |
<-finished // wait until done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment