Skip to content

Instantly share code, notes, and snippets.

@PeteGabriel
Created February 28, 2020 09:05
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/3a28770ddaad5a626b1215ca9b508fa3 to your computer and use it in GitHub Desktop.
Save PeteGabriel/3a28770ddaad5a626b1215ca9b508fa3 to your computer and use it in GitHub Desktop.
func main() {
naturals := make(chan int)
squares := make(chan int)
//Counter
//implicit conversion
go counter(naturals)
//Squarer
//implicit conversion
go square(naturals, squares)
for s := range squares {
fmt.Println(s)
}
}
func counter(into chan<- int){
for x := 0; x < 10; x++ {
into <- x
}
close(into)
}
//from = receive-only channel of int
//into = send-only channel of int
func square(from <-chan int, into chan<- int) {
for x := range from {
into <- x * x
}
close(into)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment