Syncronize all observers in Run()
With the introduction of a sync.WaitGroup we now wait for all observers to finished before Run() returns
This commit is contained in:
parent
edd9212e89
commit
65a8d52b7a
@ -9,6 +9,7 @@ import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Scanner represents an engine for scanning for a specific symbol in all
|
||||
@ -122,6 +123,7 @@ func (S *Scanner) Run() error {
|
||||
|
||||
proc.Close()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
for _, pinfo := range infos {
|
||||
var pid_s = pinfo.Name()
|
||||
|
||||
@ -135,18 +137,20 @@ func (S *Scanner) Run() error {
|
||||
} else {
|
||||
// Notify the observers.
|
||||
for n, observer := range S.observers {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
err = observer(pid, offset)
|
||||
if err != nil {
|
||||
S.setErrorf("S.observer[%d] error: %v", n, err)
|
||||
// TODO: propagate errors from all Observers.
|
||||
}
|
||||
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
return S.err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user