提交 71790c19 编写于 作者: T TommyLike

Add wg for result collection threads

上级 aee1bc7f
...@@ -59,6 +59,7 @@ func buildSigCommand() *cobra.Command { ...@@ -59,6 +59,7 @@ func buildSigCommand() *cobra.Command {
func CheckSigRepo() error { func CheckSigRepo() error {
var wg sync.WaitGroup var wg sync.WaitGroup
var endwg sync.WaitGroup
var totalProjects []string var totalProjects []string
var scanProjects []string var scanProjects []string
var invalidProjects []string var invalidProjects []string
...@@ -73,15 +74,19 @@ func CheckSigRepo() error { ...@@ -73,15 +74,19 @@ func CheckSigRepo() error {
resultChannel := make(chan string, 50) resultChannel := make(chan string, 50)
go func() { go func() {
endwg.Add(1)
for rs := range resultChannel { for rs := range resultChannel {
totalProjects = append(totalProjects, rs) totalProjects = append(totalProjects, rs)
} }
endwg.Done()
}() }()
go func() { go func() {
endwg.Add(1)
for rs := range sigChannel { for rs := range sigChannel {
scanProjects = append(scanProjects, rs) scanProjects = append(scanProjects, rs)
} }
endwg.Done()
}() }()
// Running 5 workers to collect the projects status // Running 5 workers to collect the projects status
...@@ -96,11 +101,16 @@ func CheckSigRepo() error { ...@@ -96,11 +101,16 @@ func CheckSigRepo() error {
scanner := NewDirScanner("") scanner := NewDirScanner("")
err := scanner.ScanSigYaml(sigRepoCheck.FileName, sigChannel) err := scanner.ScanSigYaml(sigRepoCheck.FileName, sigChannel)
//Wait all gitee query threads to be finished
wg.Wait() wg.Wait()
//Close the result channels
close(resultChannel) close(resultChannel)
//Wait all result collection threads to be finished
endwg.Wait()
if err != nil { if err != nil {
return err return err
} }
//fmt.Printf("this is the total projects: \n %s", strings.Join(totalProjects, ";"))
for _, scan := range scanProjects { for _, scan := range scanProjects {
if !Find(totalProjects, scan) { if !Find(totalProjects, scan) {
......
文件已添加
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册