Skip to content

Instantly share code, notes, and snippets.

@xjunior
Created June 10, 2015 16:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xjunior/0ad6c4d8d23b7e78429d to your computer and use it in GitHub Desktop.
Save xjunior/0ad6c4d8d23b7e78429d to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
"sync"
)
func timedPrint(number int64, group *sync.WaitGroup) {
time.Sleep(time.Duration(number) * time.Millisecond)
fmt.Println(number)
group.Done()
}
func timeSort(numbers []int64, group *sync.WaitGroup) {
for _, number := range numbers {
group.Add(1)
go timedPrint(number, group)
}
}
func main() {
unsorted := []int64{10, 4, 20, 13, 41}
var group sync.WaitGroup
timeSort(unsorted, &group)
group.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment