diff options
author | Reto Brunner <reto@labrat.space> | 2020-02-15 14:14:46 +0100 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2020-02-16 10:41:18 -0500 |
commit | 8d216ab10e6d43c44ca47ccd44fe7f3d40f1b1c3 (patch) | |
tree | 55578fddf1bebe250a4204d2568a7e9066ae261f /worker/notmuch/worker.go | |
parent | bb09694f07a1ff281be0e14a07b6576c9949442f (diff) | |
download | aerc-8d216ab10e6d43c44ca47ccd44fe7f3d40f1b1c3.tar.gz |
notmuch: add internal event loop
Diffstat (limited to 'worker/notmuch/worker.go')
-rw-r--r-- | worker/notmuch/worker.go | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/worker/notmuch/worker.go b/worker/notmuch/worker.go index 43d60e28..7480124e 100644 --- a/worker/notmuch/worker.go +++ b/worker/notmuch/worker.go @@ -28,6 +28,7 @@ var errUnsupported = fmt.Errorf("unsupported command") type worker struct { w *types.Worker + nmEvents chan eventType query string uidStore *uidstore.Store nameQueryMap map[string]string @@ -38,23 +39,34 @@ type worker struct { // NewWorker creates a new maildir worker with the provided worker. func NewWorker(w *types.Worker) (types.Backend, error) { - return &worker{w: w}, nil + events := make(chan eventType, 20) + return &worker{w: w, + nmEvents: events}, nil } // Run starts the worker's message handling loop. func (w *worker) Run() { for { - action := <-w.w.Actions - msg := w.w.ProcessAction(action) - if err := w.handleMessage(msg); err == errUnsupported { - w.w.PostMessage(&types.Unsupported{ - Message: types.RespondTo(msg), - }, nil) - } else if err != nil { - w.w.PostMessage(&types.Error{ - Message: types.RespondTo(msg), - Error: err, - }, nil) + select { + case action := <-w.w.Actions: + msg := w.w.ProcessAction(action) + if err := w.handleMessage(msg); err == errUnsupported { + w.w.PostMessage(&types.Unsupported{ + Message: types.RespondTo(msg), + }, nil) + w.w.Logger.Printf("ProcessAction(%T) unsupported: %v", msg, err) + } else if err != nil { + w.w.PostMessage(&types.Error{ + Message: types.RespondTo(msg), + Error: err, + }, nil) + w.w.Logger.Printf("ProcessAction(%T) failure: %v", msg, err) + } + case nmEvent := <-w.nmEvents: + err := w.handleNotmuchEvent(nmEvent) + if err != nil { + w.w.Logger.Printf("notmuch event failure: %v", err) + } } } } |