Last active
February 28, 2020 08:32
-
-
Save PeteGabriel/6e9e3b34301421fe34caaca1d040cc51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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