PageRenderTime 122ms CodeModel.GetById 40ms app.highlight 1ms RepoModel.GetById 79ms app.codeStats 0ms

/src/thread/gen.go

https://code.google.com/p/goexample/
Go | 27 lines | 15 code | 8 blank | 4 comment | 2 complexity | b8e9a5d79b1ec3663aa4a84889066c34 MD5 | raw file
 1// Copyright 2010 The Go Example Authors. All rights reserved.
 2// Use of this source code is governed by a BSD-style
 3// license that can be found in the LICENSE file.
 4
 5package main
 6
 7import "fmt"
 8
 9func generate(ch chan int){
10	for i:=2;;i++ {
11		ch <- i
12	}
13}
14
15func main() {
16	// Create a new Channel
17	ch := make(chan int)
18
19	go generate(ch) // Start generate() as a goroutine.
20
21	for {
22		prime :=<-ch // Receive value from channel
23
24		fmt.Println(prime)
25	
26	}
27}