Grokking Concurrency in Go
0% completed
Generators
A generator is a function that returns a channel and starts a goroutine that sends a sequence of values into it. The caller receives the values one at a time with for range, and the goroutine closes the channel after the last value. The caller has no reference to the goroutine. It has only a receive-only channel that produces values until it is closed.
The pattern combines three ideas from earlier chapters. A goroutine owns the channel it writes. A receive-only return type stops the caller from sending or closing. Finally, close signals that no more values will come
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%