summary refs log tree commit diff stats
diff options
context:
space:
mode:
-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)
+			}
 		}
 	}
 }