diff options
author | Simon Ser <contact@emersion.fr> | 2019-05-19 09:50:17 +0000 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-05-19 11:51:20 -0400 |
commit | 34dd6bc6354cd3592ed51da83de1a0839e08a37d (patch) | |
tree | 6c65d68427ddd537eff30d44841ae8f7912f08c8 | |
parent | 7c6325977b55385bc65f0a08f4da8ed6dfede52a (diff) | |
download | aerc-34dd6bc6354cd3592ed51da83de1a0839e08a37d.tar.gz |
worker/types/worker: set ID before sending message
The previous code set the message ID after sending it, which could result in
the receiver reading the ID before it's set.
-rw-r--r-- | worker/types/worker.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/worker/types/worker.go b/worker/types/worker.go index e2af61fb..5647ae3a 100644 --- a/worker/types/worker.go +++ b/worker/types/worker.go @@ -30,11 +30,13 @@ func NewWorker(logger *log.Logger) *Worker { } } -func (worker *Worker) setCallback(msg WorkerMessage, - cb func(msg WorkerMessage)) { - +func (worker *Worker) setId(msg WorkerMessage) { msg.setId(nextId) nextId++ +} + +func (worker *Worker) setCallback(msg WorkerMessage, + cb func(msg WorkerMessage)) { if cb != nil { worker.mutex.Lock() @@ -59,6 +61,8 @@ func (worker *Worker) getCallback(msg WorkerMessage) (func(msg WorkerMessage), func (worker *Worker) PostAction(msg WorkerMessage, cb func(msg WorkerMessage)) { + worker.setId(msg) + if resp := msg.InResponseTo(); resp != nil { worker.Logger.Printf("(ui)=> %T:%T\n", msg, resp) } else { @@ -72,6 +76,8 @@ func (worker *Worker) PostAction(msg WorkerMessage, func (worker *Worker) PostMessage(msg WorkerMessage, cb func(msg WorkerMessage)) { + worker.setId(msg) + if resp := msg.InResponseTo(); resp != nil { worker.Logger.Printf("->(ui) %T:%T\n", msg, resp) } else { |