summary refs log tree commit diff stats
path: root/worker/worker.go
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-02-01 18:42:03 -0500
committerDrew DeVault <sir@cmpwn.com>2018-02-01 18:42:03 -0500
commitd24e4712a45e03d79fa1ccb71d00c5b830d5a305 (patch)
tree61e2ba149d7b1197bdc5180200a6e087844131fe /worker/worker.go
parentee73c419507ef74a78ddd6a3466b605cba140b68 (diff)
downloadaerc-d24e4712a45e03d79fa1ccb71d00c5b830d5a305.tar.gz
Reduce boilerplate in worker/UI
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 b665884..439ab64 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
 }