/src/thread/gen.go
https://code.google.com/p/goexample/ · Go · 27 lines · 15 code · 8 blank · 4 comment · 3 complexity · b8e9a5d79b1ec3663aa4a84889066c34 MD5 · raw file
- // Copyright 2010 The Go Example Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style
- // license that can be found in the LICENSE file.
-
- package main
-
- import "fmt"
-
- func generate(ch chan int){
- for i:=2;;i++ {
- ch <- i
- }
- }
-
- func main() {
- // Create a new Channel
- ch := make(chan int)
-
- go generate(ch) // Start generate() as a goroutine.
-
- for {
- prime :=<-ch // Receive value from channel
-
- fmt.Println(prime)
-
- }
- }