From 8d216ab10e6d43c44ca47ccd44fe7f3d40f1b1c3 Mon Sep 17 00:00:00 2001 From: Reto Brunner Date: Sat, 15 Feb 2020 14:14:46 +0100 Subject: notmuch: add internal event loop --- worker/notmuch/eventhandlers.go | 9 +++++++++ worker/notmuch/events.go | 5 +++++ worker/notmuch/worker.go | 36 ++++++++++++++++++++++++------------ 3 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 worker/notmuch/eventhandlers.go create mode 100644 worker/notmuch/events.go (limited to 'worker/notmuch') diff --git a/worker/notmuch/eventhandlers.go b/worker/notmuch/eventhandlers.go new file mode 100644 index 0000000..39027b6 --- /dev/null +++ b/worker/notmuch/eventhandlers.go @@ -0,0 +1,9 @@ +package notmuch + +func (w *worker) handleNotmuchEvent(et eventType) error { + switch ev := et.(type) { + default: + _ = ev + return errUnsupported + } +} diff --git a/worker/notmuch/events.go b/worker/notmuch/events.go new file mode 100644 index 0000000..df35b21 --- /dev/null +++ b/worker/notmuch/events.go @@ -0,0 +1,5 @@ +package notmuch + +type eventType interface{} + +type event struct{} diff --git a/worker/notmuch/worker.go b/worker/notmuch/worker.go index 43d60e2..7480124 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) + } } } } -- cgit v1.2.3