Created
August 21, 2018 17:25
-
-
Save picatz/33ce61525f429961afe73542893f8003 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
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