Skip to content

Commit

Permalink
fix waiting logic
Browse files Browse the repository at this point in the history
  • Loading branch information
noboruma committed Jul 2, 2024
1 parent ce3abe1 commit 7d445e3
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions pkg/scan/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,15 @@ func (s *Scanner) Scan(ctx *tasks.ScanContext, stype ScanType, namespace, id str
results := make(chan []output.IOCFound)
defer close(results)

done := make(chan bool)
defer close(done)

m := [2][]output.IOCFound{}
i := 0

wg.Add(1)
go func() {
defer wg.Done()
for {
select {
case malwares := <-results:
for _, malware := range malwares {
outputFn(malware, scanID)
}
case <-done:
logrus.Info("scan completed")
return
for malwares := range results {
for _, malware := range malwares {
outputFn(malware, scanID)
}
}
}()
Expand Down Expand Up @@ -140,8 +131,6 @@ func (s *Scanner) Scan(ctx *tasks.ScanContext, stype ScanType, namespace, id str
i %= len(m)
})

done <- true

wg.Wait()
return nil
}

0 comments on commit 7d445e3

Please sign in to comment.