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"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Scanner represents an engine for scanning for a specific symbol in all
|
// Scanner represents an engine for scanning for a specific symbol in all
|
||||||
@ -122,6 +123,7 @@ func (S *Scanner) Run() error {
|
|||||||
|
|
||||||
proc.Close()
|
proc.Close()
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
for _, pinfo := range infos {
|
for _, pinfo := range infos {
|
||||||
var pid_s = pinfo.Name()
|
var pid_s = pinfo.Name()
|
||||||
|
|
||||||
@ -135,18 +137,20 @@ func (S *Scanner) Run() error {
|
|||||||
} else {
|
} else {
|
||||||
// Notify the observers.
|
// Notify the observers.
|
||||||
for n, observer := range S.observers {
|
for n, observer := range S.observers {
|
||||||
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
err = observer(pid, offset)
|
err = observer(pid, offset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
S.setErrorf("S.observer[%d] error: %v", n, err)
|
S.setErrorf("S.observer[%d] error: %v", n, err)
|
||||||
// TODO: propagate errors from all Observers.
|
// TODO: propagate errors from all Observers.
|
||||||
}
|
}
|
||||||
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
return S.err
|
return S.err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user