Skip to content

Instantly share code, notes, and snippets.

@iporsut
Created June 9, 2011 17:54
Show Gist options
  • Save iporsut/1017302 to your computer and use it in GitHub Desktop.
Save iporsut/1017302 to your computer and use it in GitHub Desktop.
learn goroutine and channel
package main
import (
"fmt"
)
func generate() chan int {
ch := make(chan int)
go func() {
for i := 2; ;i++ {
ch <- i
}
}()
return ch
}
func goPrint(ch chan int) {
for i := 1; i <= 100; i++ {
fmt.Print(<-ch)
}
}
func main() {
go goPrint(generate())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment