aboutsummaryrefslogtreecommitdiff
path: root/worker/types/messages.go
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2019-05-19 09:50:19 +0000
committerDrew DeVault <sir@cmpwn.com>2019-05-19 11:51:22 -0400
commitf27db333052aa24a0aad135c09ce7969bf31bc56 (patch)
tree92acd47ded90d7c1a5e0c283c446122ff9aef594 /worker/types/messages.go
parent34dd6bc6354cd3592ed51da83de1a0839e08a37d (diff)
worker/types/worker: make ID allocation atomic
Message IDs are allocated for both messages from UI to workers and the other way around. Hence, the global nextId variable is accessed from multiple goroutines. Instead, use atomic to access the global counter.
Diffstat (limited to 'worker/types/messages.go')
-rw-r--r--worker/types/messages.go10
1 files changed, 5 insertions, 5 deletions
diff --git a/worker/types/messages.go b/worker/types/messages.go
index 0cb6eeb..eb54a15 100644
--- a/worker/types/messages.go
+++ b/worker/types/messages.go
@@ -12,13 +12,13 @@ import (
type WorkerMessage interface {
InResponseTo() WorkerMessage
- getId() int
- setId(id int)
+ getId() int64
+ setId(id int64)
}
type Message struct {
inResponseTo WorkerMessage
- id int
+ id int64
}
func RespondTo(msg WorkerMessage) Message {
@@ -31,11 +31,11 @@ func (m Message) InResponseTo() WorkerMessage {
return m.inResponseTo
}
-func (m Message) getId() int {
+func (m Message) getId() int64 {
return m.id
}
-func (m Message) setId(id int) {
+func (m Message) setId(id int64) {
m.id = id
}