Skip to content

Instantly share code, notes, and snippets.

@cideM
Created September 20, 2021 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cideM/8f7728d8b4cb208eb26e88e0c19359b6 to your computer and use it in GitHub Desktop.
Save cideM/8f7728d8b4cb208eb26e88e0c19359b6 to your computer and use it in GitHub Desktop.
Producer Consumer
package main
import (
"log"
)
func producer(strings []string) (<-chan string, error) {
outChannel := make(chan string)
for _, s := range strings {
outChannel <- s
}
return outChannel, nil
}
func sink(values <-chan string) {
for value := range values {
log.Println(value)
}
}
func main() {
source := []string{"foo", "bar", "bax"}
outputChannel, err := producer(source)
if err != nil {
log.Fatal(err)
}
sink(outputChannel)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment