Created
December 30, 2016 16:51
-
-
Save index0h/0d896c8494162258658d586a0ebe8ba4 to your computer and use it in GitHub Desktop.
example goroutine
This file contains hidden or 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
index0h@home-pc:/tmp$ cat test.go | |
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
func pinger(c chan string) { | |
for i := 0; ; i++ { | |
c <- "ping" | |
} | |
} | |
func printer(c chan string) { | |
for { | |
msg := <- c | |
fmt.Println(msg) | |
time.Sleep(time.Second * 1) | |
} | |
} | |
func main() { | |
var c chan string = make(chan string) | |
go pinger(c) | |
go printer(c) | |
var input string | |
fmt.Scanln(&input) | |
} | |
index0h@home-pc:/tmp$ go run ./test.go | |
ping | |
ping | |
ping | |
ping |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment