notmuch: add internal event loop

This commit is contained in:
Reto Brunner 2020-02-15 14:14:46 +01:00 committed by Drew DeVault
parent bb09694f07
commit 8d216ab10e
3 changed files with 38 additions and 12 deletions

View file

@ -0,0 +1,9 @@
package notmuch
func (w *worker) handleNotmuchEvent(et eventType) error {
switch ev := et.(type) {
default:
_ = ev
return errUnsupported
}
}

5
worker/notmuch/events.go Normal file
View file

@ -0,0 +1,5 @@
package notmuch
type eventType interface{}
type event struct{}

View file

@ -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)
}
}
}
}