Skip to content

Instantly share code, notes, and snippets.

@rogerwelin
Created September 4, 2018 11:49
Show Gist options
  • Select an option

  • Save rogerwelin/2c23fc3f25305de218919c5844804714 to your computer and use it in GitHub Desktop.

Select an option

Save rogerwelin/2c23fc3f25305de218919c5844804714 to your computer and use it in GitHub Desktop.
unbuffered-channel
package main
import (
"fmt"
)
func printer(msg string, ch chan<- string) {
ch <- msg
}
func main() {
stuff := []string{"one", "two", "three", "four", "five", "six", "seven"}
stringStream := make(chan string)
fmt.Println("init")
go func() {
for _, item := range stuff {
printer(item, stringStream)
}
close(stringStream)
}()
for item := range stringStream {
fmt.Println(item)
}
fmt.Println("end")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment