Skip to content

Instantly share code, notes, and snippets.

@picatz
Created August 21, 2018 17:25
Show Gist options
  • Save picatz/33ce61525f429961afe73542893f8003 to your computer and use it in GitHub Desktop.
Save picatz/33ce61525f429961afe73542893f8003 to your computer and use it in GitHub Desktop.
func newProducer(readTimeout time.Duration, products ...string) <-chan string {
results := make(chan string)
go func() {
defer close(results)
for _, product := range products {
select {
case results <- product:
// didn't time out
case <-time.After(readTimeout):
return
}
}
}()
return results
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment