Skip to content

Instantly share code, notes, and snippets.

@PeteGabriel
Last active February 28, 2020 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PeteGabriel/6e9e3b34301421fe34caaca1d040cc51 to your computer and use it in GitHub Desktop.
Save PeteGabriel/6e9e3b34301421fe34caaca1d040cc51 to your computer and use it in GitHub Desktop.
func main() {
naturals := make(chan int)
squares := make(chan int)
//Counter
go func() {
for x := 0; x < 10; x++ {
naturals <- x
}
close(naturals)
}()
//Squarer
go func() {
for x := range naturals {
squares <- x * x
}
close(squares)
}()
for s := range squares {
fmt.Println(s)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment