Skip to content

Instantly share code, notes, and snippets.

@repustate
Created March 7, 2013 02:27
Show Gist options
  • Save repustate/5105120 to your computer and use it in GitHub Desktop.
Save repustate/5105120 to your computer and use it in GitHub Desktop.
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