notmuch: add internal event loop
This commit is contained in:
parent
bb09694f07
commit
8d216ab10e
|
@ -0,0 +1,9 @@
|
||||||
|
package notmuch
|
||||||
|
|
||||||
|
func (w *worker) handleNotmuchEvent(et eventType) error {
|
||||||
|
switch ev := et.(type) {
|
||||||
|
default:
|
||||||
|
_ = ev
|
||||||
|
return errUnsupported
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package notmuch
|
||||||
|
|
||||||
|
type eventType interface{}
|
||||||
|
|
||||||
|
type event struct{}
|
|
@ -28,6 +28,7 @@ var errUnsupported = fmt.Errorf("unsupported command")
|
||||||
|
|
||||||
type worker struct {
|
type worker struct {
|
||||||
w *types.Worker
|
w *types.Worker
|
||||||
|
nmEvents chan eventType
|
||||||
query string
|
query string
|
||||||
uidStore *uidstore.Store
|
uidStore *uidstore.Store
|
||||||
nameQueryMap map[string]string
|
nameQueryMap map[string]string
|
||||||
|
@ -38,23 +39,34 @@ type worker struct {
|
||||||
|
|
||||||
// NewWorker creates a new maildir worker with the provided worker.
|
// NewWorker creates a new maildir worker with the provided worker.
|
||||||
func NewWorker(w *types.Worker) (types.Backend, error) {
|
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.
|
// Run starts the worker's message handling loop.
|
||||||
func (w *worker) Run() {
|
func (w *worker) Run() {
|
||||||
for {
|
for {
|
||||||
action := <-w.w.Actions
|
select {
|
||||||
msg := w.w.ProcessAction(action)
|
case action := <-w.w.Actions:
|
||||||
if err := w.handleMessage(msg); err == errUnsupported {
|
msg := w.w.ProcessAction(action)
|
||||||
w.w.PostMessage(&types.Unsupported{
|
if err := w.handleMessage(msg); err == errUnsupported {
|
||||||
Message: types.RespondTo(msg),
|
w.w.PostMessage(&types.Unsupported{
|
||||||
}, nil)
|
Message: types.RespondTo(msg),
|
||||||
} else if err != nil {
|
}, nil)
|
||||||
w.w.PostMessage(&types.Error{
|
w.w.Logger.Printf("ProcessAction(%T) unsupported: %v", msg, err)
|
||||||
Message: types.RespondTo(msg),
|
} else if err != nil {
|
||||||
Error: err,
|
w.w.PostMessage(&types.Error{
|
||||||
}, nil)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue