Created
September 20, 2021 08:21
-
-
Save cideM/8f7728d8b4cb208eb26e88e0c19359b6 to your computer and use it in GitHub Desktop.
Producer Consumer
This file contains 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 ( | |
"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