This is not a great repo. It's about following the Goggle I/O - Go Concurrency patterns presentation, learning about Go concurrency, patterns, etc.
Function that returns a channel
// this is a generator function
func boring(msg string) <-chan string { // Returns receive-only channel of strings
c := make(chan string)
go func() { // we launch the gorutine from inside the function
for i := 0; ; i++ {
c <- fmt.Sprintf("%s %d", msg, i)
time.Sleep(time.Duration(rand.Intn(1e3)) * time.Millisecond)
}
}()
return c // returns the channel to the caller
}
Get two (many) gorutines and send each result via a channel.
Two examples:
- One with two gorutines
- One with one gorutine and a select