Skip to content

Instantly share code, notes, and snippets.

@picatz
Last active August 21, 2018 15:55
Show Gist options
  • Save picatz/30c54fe493ca1b205e9ea17894bf309e to your computer and use it in GitHub Desktop.
Save picatz/30c54fe493ca1b205e9ea17894bf309e to your computer and use it in GitHub Desktop.
package main
import "fmt"
func newProducer(products ...string) <-chan string {
results := make(chan string)
go func() {
defer close(results)
for _, product := range products {
results <- product
}
}()
return results
}
func main() {
for result := range newProducer("A", "B", "C", "E", "F", "G") {
fmt.Println(result)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment