Skip to content

Instantly share code, notes, and snippets.

@suzuken
Created March 23, 2016 02:44
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 suzuken/57ed19af17dc0f3af595 to your computer and use it in GitHub Desktop.
Save suzuken/57ed19af17dc0f3af595 to your computer and use it in GitHub Desktop.
// original: http://dave.cheney.net/2014/03/19/channel-axioms
package main
import (
"fmt"
"sync"
)
func main() {
var c = make(chan int, 100)
done := make(chan bool, 1)
var wg sync.WaitGroup
for i := 0; i < 10; i++ {
go func() {
defer wg.Done()
wg.Add(1)
for j := 0; j < 10; j++ {
c <- j
}
}()
}
go func() {
wg.Wait()
done <- true
}()
<-done
for i := 0; i < 100; i++ {
fmt.Println(<-c)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment