-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Capítulo 22, Exercício 6 (Nível: 10) #82
Comments
https://play.golang.org/p/LSXTY6Qu2Qb
Output
|
`package main import "fmt" func main() { func reader(comChannel chan int) { func sender(channel chan int, totalMsgs int) { |
package main
import "fmt"
func main() {
canal1 := make(chan int)
canal2 := receber(canal1)
imprime(canal2)
//fmt.Println()
}
func receber(canal1 chan int) <-chan int {
go func() {
for i := 0; i < 100; i++ {
canal1 <- i
}
close(canal1)
}()
return canal1
}
func imprime(s <-chan int) {
for v := range s {
fmt.Println(v)
}
} |
package main
import (
"fmt"
)
func main() {
c := make(chan int)
go func() {
for i := 1; i <= 100; i++ {
c <- i
}
close(c)
}()
for {
select {
case v, ok := <- c:
if ok {
fmt.Println(v)
} else {
fmt.Println("Não há mais valores no canal c, \nvalor default ->", v)
return
}
}
}
} |
Exercício: Capítulo 22, Exercício 6 (Nível: 10)
Use esta thread para compartilhar sua solução, discutir o exercício com os colegas e pedir ajuda caso tenha dificuldades!
The text was updated successfully, but these errors were encountered: