Created
March 7, 2013 02:27
-
-
Save repustate/5105120 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" | |
"strconv" | |
) | |
func makeCakeAndSend(cs chan string) { | |
for i := 1; i<=20; i++ { | |
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) { | |
for i := 1; i<=20; i++ { | |
s := <-cs //get whatever cake is on the channel | |
fmt.Println("Packing received cake: ", s) | |
} | |
} | |
func main() { | |
cs := make(chan string) | |
go makeCakeAndSend(cs) | |
go receiveCakeAndPack(cs) | |
//sleep for a while so that the program doesn’t exit immediately | |
time.Sleep(4 * 1e9) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment