about summary refs log tree commit diff stats
path: root/worker/notmuch
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 /worker/notmuch
parentbb09694f07a1ff281be0e14a07b6576c9949442f (diff)
downloadaerc-8d216ab10e6d43c44ca47ccd44fe7f3d40f1b1c3.tar.gz
notmuch: add internal event loop
Diffstat (limited to 'worker/notmuch')
-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)
+			}
 		}
 	}
 }
>
5a2cb154 ^















762107fd ^
5a2cb154 ^
4a4a392d ^













ec73ed12 ^
4a4a392d ^



86351aaf ^





















ec73ed12 ^
86351aaf ^











ec73ed12 ^
86351aaf ^



ec73ed12 ^
86351aaf ^

ec73ed12 ^
86351aaf ^


ec73ed12 ^
86351aaf ^






































5a2cb154 ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169