Created
December 18, 2014 11:10
-
-
Save takkkun/d40a6ff29797caefa5c4 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" | |
"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