Created
May 31, 2014 16:53
-
-
Save wingyplus/235a7f8e141970be80a7 to your computer and use it in GitHub Desktop.
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 "fmt" | |
func sender(to chan string, done chan bool) { | |
for { | |
select { | |
case t := <-to: | |
fmt.Println(t) | |
case <-done: | |
break | |
} | |
} | |
} | |
func main() { | |
strs := []string{ | |
"a", | |
"b", | |
"c", | |
"d", | |
} | |
ch := make(chan string, len(strs)) | |
done := make(chan bool) | |
go sender(ch, done) | |
for _, v := range strs { | |
ch <- v | |
} | |
done <- true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment