diff options
author | Drew DeVault <sir@cmpwn.com> | 2019-05-15 19:41:21 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-05-15 19:41:21 -0400 |
commit | b0bf09b98fc038c1bc9921d568c06260b7448a15 (patch) | |
tree | acad72b3ec224d95c551a11ba35cf4e8522641e1 /worker/types/worker.go | |
parent | 52b318127fe7ec001ca824947193b2cb7b0ebda6 (diff) | |
download | aerc-b0bf09b98fc038c1bc9921d568c06260b7448a15.tar.gz |
Copy sent emails to the Sent folder
Or rather, to a user-specified folder
Diffstat (limited to 'worker/types/worker.go')
-rw-r--r-- | worker/types/worker.go | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/worker/types/worker.go b/worker/types/worker.go index 0ed216a..e2af61f 100644 --- a/worker/types/worker.go +++ b/worker/types/worker.go @@ -5,6 +5,8 @@ import ( "sync" ) +var nextId int = 1 + type Backend interface { Run() } @@ -15,7 +17,7 @@ type Worker struct { Messages chan WorkerMessage Logger *log.Logger - callbacks map[WorkerMessage]func(msg WorkerMessage) // protected by mutex + callbacks map[int]func(msg WorkerMessage) // protected by mutex mutex sync.Mutex } @@ -24,16 +26,19 @@ func NewWorker(logger *log.Logger) *Worker { Actions: make(chan WorkerMessage, 50), Messages: make(chan WorkerMessage, 50), Logger: logger, - callbacks: make(map[WorkerMessage]func(msg WorkerMessage)), + callbacks: make(map[int]func(msg WorkerMessage)), } } func (worker *Worker) setCallback(msg WorkerMessage, cb func(msg WorkerMessage)) { + msg.setId(nextId) + nextId++ + if cb != nil { worker.mutex.Lock() - worker.callbacks[msg] = cb + worker.callbacks[msg.getId()] = cb worker.mutex.Unlock() } } @@ -41,8 +46,11 @@ func (worker *Worker) setCallback(msg WorkerMessage, func (worker *Worker) getCallback(msg WorkerMessage) (func(msg WorkerMessage), bool) { + if msg == nil { + return nil, false + } worker.mutex.Lock() - cb, ok := worker.callbacks[msg] + cb, ok := worker.callbacks[msg.getId()] worker.mutex.Unlock() return cb, ok |