Skip to content

Instantly share code, notes, and snippets.

@kachayev
Created August 1, 2013 15:00
Show Gist options
  • Save kachayev/6132217 to your computer and use it in GitHub Desktop.
Save kachayev/6132217 to your computer and use it in GitHub Desktop.
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