about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorReto Brunner <reto@labrat.space>2020-02-15 14:14:46 +0100
committerDrew DeVault <sir@cmpwn.com>2020-02-16 10:41:18 -0500
commit8d216ab10e6d43c44ca47ccd44fe7f3d40f1b1c3 (patch)
tree55578fddf1bebe250a4204d2568a7e9066ae261f
parentbb09694f07a1ff281be0e14a07b6576c9949442f (diff)
downloadaerc-8d216ab10e6d43c44ca47ccd44fe7f3d40f1b1c3.tar.gz
notmuch: add internal event loop
-rw-r--r--worker/notmuch/eventhandlers.go9
-rw-r--r--worker/notmuch/events.go5
-rw-r--r--worker/notmuch/worker.go36
3 files changed, 38 insertions, 12 deletions
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)
+			}
 		}
 	}
 }