Last active
August 21, 2018 15:55
-
-
Save picatz/30c54fe493ca1b205e9ea17894bf309e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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