aboutsummaryrefslogtreecommitdiffstats
path: root/worker/worker.go
diff options
context:
space:
mode:
Diffstat (limited to 'worker/worker.go')
-rw-r--r--worker/worker.go20
1 files changed, 11 insertions, 9 deletions
diff --git a/worker/worker.go b/worker/worker.go
index b6658849..439ab648 100644
--- a/worker/worker.go
+++ b/worker/worker.go
@@ -9,22 +9,24 @@ import (
"net/url"
)
-type Worker interface {
- GetMessages() chan types.WorkerMessage
- PostAction(types.WorkerMessage)
- Run()
-}
-
// Guesses the appropriate worker type based on the given source string
-func NewWorker(source string, logger *log.Logger) (Worker, error) {
+func NewWorker(source string, logger *log.Logger) (*types.Worker, error) {
u, err := url.Parse(source)
if err != nil {
return nil, err
}
+ worker := &types.Worker{
+ Actions: make(chan types.WorkerMessage, 50),
+ Callbacks: make(map[types.WorkerMessage]func(msg types.WorkerMessage)),
+ Messages: make(chan types.WorkerMessage, 50),
+ Logger: logger,
+ }
switch u.Scheme {
case "imap":
case "imaps":
- return imap.NewIMAPWorker(logger), nil
+ worker.Backend = imap.NewIMAPWorker(worker)
+ default:
+ return nil, fmt.Errorf("Unknown backend %s", u.Scheme)
}
- return nil, fmt.Errorf("Unknown backend %s", u.Scheme)
+ return worker, nil
}