Created
June 10, 2015 16:50
-
-
Save xjunior/0ad6c4d8d23b7e78429d to your computer and use it in GitHub Desktop.
This file contains hidden or 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" | |
"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