Skip to content

Commit

Permalink
Adding waiting groups to wait for all routines finishing
Browse files Browse the repository at this point in the history
  • Loading branch information
fedir committed May 13, 2018
1 parent 2deae55 commit 281ef75
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 5 additions & 2 deletions data.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ package main

import (
"fmt"
"sync"
"time"

"github.com/fedir/ghstat/github"
)

func repositoryData(rKey string, tmpFolder string, debug bool, dataChan chan Repository) {
func repositoryData(rKey string, tmpFolder string, debug bool, dataChan chan Repository, wg *sync.WaitGroup) {

defer wg.Done()

r := new(Repository)

Expand Down Expand Up @@ -43,7 +46,7 @@ func repositoryData(rKey string, tmpFolder string, debug bool, dataChan chan Rep
r.AuthorLocation = authorData.Location
}
} else {
r.Author = "[Account removed]"
r.Author = "[Unknown account]"
}

r.ClosedIssues = 0
Expand Down
6 changes: 5 additions & 1 deletion ghstat.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"flag"
"os"
"strings"
"sync"

"github.com/fedir/ghstat/github"
)
Expand Down Expand Up @@ -58,14 +59,17 @@ func main() {
csvFilePath = "result.csv"
}
var ghData = []Repository{}
var wg sync.WaitGroup
wg.Add(len(repositoriesKeys))

dataChan := make(chan Repository, len(repositoriesKeys))
for _, rKey := range repositoriesKeys {
go repositoryData(rKey, *tmpFolder, *debug, dataChan)
go repositoryData(rKey, *tmpFolder, *debug, dataChan, &wg)
}
for range repositoriesKeys {
ghData = append(ghData, <-dataChan)
}
wg.Wait()
rateAndPrintGreetings(ghData)
writeCSVStatistics(ghData, csvFilePath)
}
Expand Down

0 comments on commit 281ef75

Please sign in to comment.