You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think in the context of what this step is suppose to illustrate creating the channel with the capacity of the number of fibs you want to calculate is miss-leading.
For this to work the channel needs to have (and should have) a capacity of one (basically synchronizing the fib goroutine with the main goroutine (between calculating one number and displaying it)).
func main() {
c := make(chan int)
go fibonacci(10, c)
for i := range c {
fmt.Println(i)
}
}
The text was updated successfully, but these errors were encountered:
The code shows how range on a channel will continue until the channel is closed by the sending side. The capacity in the channel is there to allow fibonacci() to complete, sending all output over the channel, and close the channel if that (by scheduling chance) happens before the for loop starts reading from the channel.
Context: https://tour.golang.org/concurrency/4
Hi All,
I think in the context of what this step is suppose to illustrate creating the channel with the capacity of the number of fibs you want to calculate is miss-leading.
For this to work the channel needs to have (and should have) a capacity of one (basically synchronizing the fib goroutine with the main goroutine (between calculating one number and displaying it)).
The text was updated successfully, but these errors were encountered: