Skip to content

Instantly share code, notes, and snippets.

@jimmysawczuk
Last active December 13, 2015 22:18
Show Gist options
  • Save jimmysawczuk/4983137 to your computer and use it in GitHub Desktop.
Save jimmysawczuk/4983137 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
)
func main() {
x := make([]chan bool, 10)
for i := 0; i < 10; i++ {
x[i] = make(chan bool)
go func(n int) {
dur, _ := time.ParseDuration(fmt.Sprintf("%ds", 10-n))
time.Sleep(dur)
fmt.Printf("Hello %d\n", n+1)
x[n] <- true
}(i)
}
for i := 0; i < 10; i++ {
<-x[i]
}
}
// Outputs:
/*
Hello 10
Hello 9
Hello 8
Hello 7
Hello 6
Hello 5
Hello 4
Hello 3
Hello 2
Hello 1
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment