From 65a8d52b7a358de1b414217797fb2858faafc9cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCr=20Kesim?= Date: Thu, 16 Jan 2020 10:18:07 +0100 Subject: [PATCH] Syncronize all observers in Run() With the introduction of a sync.WaitGroup we now wait for all observers to finished before Run() returns --- GetRuntimeAddresses/symbolyze/symbolyze.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/GetRuntimeAddresses/symbolyze/symbolyze.go b/GetRuntimeAddresses/symbolyze/symbolyze.go index d3c9f45..79af466 100644 --- a/GetRuntimeAddresses/symbolyze/symbolyze.go +++ b/GetRuntimeAddresses/symbolyze/symbolyze.go @@ -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 }