shad-go/lectures/03-goroutines/pipeline1/main.go
2020-03-12 16:45:30 +03:00

26 lines
321 B
Go

package main
import "fmt"
func main() {
naturals := make(chan int)
squares := make(chan int)
go func() { // Counter
for x := 0; ; x++ {
naturals <- x
}
}()
go func() { // Squarer
for {
x := <-naturals
squares <- x * x
}
}()
// Printer (in main goroutine)
for {
fmt.Println(<-squares)
}
}