Created
January 18, 2018 12:42
-
-
Save deividaspetraitis/986d6cdfc9bf95d96b55ccc193944c34 to your computer and use it in GitHub Desktop.
It's working!
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" | |
"time" | |
"runtime" | |
) | |
func main() { | |
fmt.Println("init") | |
ch := gen() | |
fmt.Println("run routine") | |
go gook(ch) | |
fmt.Println("continue") | |
runtime.Goexit() | |
} | |
func gook(ch chan string) { | |
for { | |
data := <-ch | |
fmt.Println(data) | |
} | |
} | |
func gen() chan string { | |
out := make(chan string) | |
go func() { | |
for { | |
time.Sleep(time.Second * 1) | |
out <- "ping" | |
} | |
}() | |
return out | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment