Skip to content

Instantly share code, notes, and snippets.

@takkkun
Created December 18, 2014 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takkkun/d40a6ff29797caefa5c4 to your computer and use it in GitHub Desktop.
Save takkkun/d40a6ff29797caefa5c4 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"strconv"
"strings"
"time"
)
func main() {
nozomi := make(chan string)
nico := make(chan string)
go generateNozomiMessage((chan<- string)(nozomi), 9)
go generateNicoMessage((chan<- string)(nico), 2)
for {
select {
case message := <-nozomi:
fmt.Println(message)
case message := <-nico:
fmt.Println(message)
}
}
}
func generateNozomiMessage(ch chan<- string, people int64) {
ch <- "うちを入れて" + strconv.FormatInt(people, 10) + "人や"
time.Sleep(777 * time.Millisecond)
generateNozomiMessage(ch, people + 1)
}
func generateNicoMessage(ch chan<- string, times int) {
ch <- strings.Repeat("にっこ", times) + "にー♪"
time.Sleep(1000 * time.Millisecond)
generateNicoMessage(ch, times + 1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment