Skip to content

Instantly share code, notes, and snippets.

@dojiong
Created January 15, 2013 06:54
Show Gist options
  • Save dojiong/4536745 to your computer and use it in GitHub Desktop.
Save dojiong/4536745 to your computer and use it in GitHub Desktop.
package main
import "fmt"
func pusher(ch chan string, data string, count int) {
for count > 0 {
ch <- data
count -= 1
}
}
func puller(ch chan string, end chan int) {
count := 0
for {
if _, ok := <- ch; !ok {
break
}
count += 1
}
end <- count
}
func main() {
data := string(make([]byte, 1024 * 1024 * 1024))
fmt.Println(len(data))
ch := make(chan string)
end_ch := make(chan int)
go puller(ch, end_ch)
go puller(ch, end_ch)
go puller(ch, end_ch)
go puller(ch, end_ch)
pusher(ch, data, 1024)
close(ch)
for i :=0; i < 4; i++ {
n := <- end_ch
fmt.Println(n)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment