Created
August 1, 2013 15:00
-
-
Save kachayev/6132217 to your computer and use it in GitHub Desktop.
Go channels tutorial (http://golangtutorials.blogspot.com/2011/06/channels-in-go.html)
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
var i int | |
func makeCakeAndSend(cs chan string) { | |
i = i + 1 | |
cakeName := "Strawberry Cake " + strconv.Itoa(i) | |
fmt.Println("Making a cake and sending ...", cakeName) | |
cs <- cakeName //send a strawberry cake | |
} | |
func receiveCakeAndPack(cs chan string) { | |
s := <-cs //get whatever cake is on the channel | |
fmt.Println("Packing received cake: ", s) | |
} | |
func main() { | |
cs := make(chan string) | |
for i := 0; i<3; i++ { | |
go makeCakeAndSend(cs) | |
go receiveCakeAndPack(cs) | |
time.Sleep(1 * 1e9) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment