diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2022-10-06 11:46:41 -0500 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-10-07 10:51:53 +0200 |
commit | bb1249164d8de6d821dcf3293f5ff2650be95481 (patch) | |
tree | 8dd0194a877a226a976baeb253cb1fe9d77fa70e /worker | |
parent | d847073bdf67a2fd8c8695dbacbe010bcbfd27c8 (diff) | |
download | aerc-bb1249164d8de6d821dcf3293f5ff2650be95481.tar.gz |
aerc: use single event loop
Combine tcell events with WorkerMessages to better synchronize state
with IO and UI. Remove Tick loop for rendering. Use events to trigger
renders.
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker')
-rw-r--r-- | worker/types/messages.go | 11 | ||||
-rw-r--r-- | worker/types/worker.go | 14 | ||||
-rw-r--r-- | worker/worker.go | 4 |
3 files changed, 21 insertions, 8 deletions
diff --git a/worker/types/messages.go b/worker/types/messages.go index 00a1a781..033450bb 100644 --- a/worker/types/messages.go +++ b/worker/types/messages.go @@ -12,11 +12,14 @@ type WorkerMessage interface { InResponseTo() WorkerMessage getId() int64 setId(id int64) + Account() string + setAccount(string) } type Message struct { inResponseTo WorkerMessage id int64 + acct string } func RespondTo(msg WorkerMessage) Message { @@ -37,6 +40,14 @@ func (m *Message) setId(id int64) { m.id = id } +func (m *Message) Account() string { + return m.acct +} + +func (m *Message) setAccount(name string) { + m.acct = name +} + // Meta-messages type Done struct { diff --git a/worker/types/worker.go b/worker/types/worker.go index b5f51496..d21a46a5 100644 --- a/worker/types/worker.go +++ b/worker/types/worker.go @@ -5,6 +5,7 @@ import ( "sync" "sync/atomic" + "git.sr.ht/~rjarry/aerc/lib/ui" "git.sr.ht/~rjarry/aerc/logging" "git.sr.ht/~rjarry/aerc/models" ) @@ -16,9 +17,9 @@ type Backend interface { } type Worker struct { - Backend Backend - Actions chan WorkerMessage - Messages chan WorkerMessage + Backend Backend + Actions chan WorkerMessage + Name string actionCallbacks map[int64]func(msg WorkerMessage) messageCallbacks map[int64]func(msg WorkerMessage) @@ -28,10 +29,10 @@ type Worker struct { sync.Mutex } -func NewWorker() *Worker { +func NewWorker(name string) *Worker { return &Worker{ Actions: make(chan WorkerMessage), - Messages: make(chan WorkerMessage, 50), + Name: name, actionCallbacks: make(map[int64]func(msg WorkerMessage)), messageCallbacks: make(map[int64]func(msg WorkerMessage)), actionQueue: list.New(), @@ -103,13 +104,14 @@ func (worker *Worker) PostMessage(msg WorkerMessage, cb func(msg WorkerMessage), ) { worker.setId(msg) + msg.setAccount(worker.Name) if resp := msg.InResponseTo(); resp != nil { logging.Debugf("PostMessage %T:%T", msg, resp) } else { logging.Debugf("PostMessage %T", msg) } - worker.Messages <- msg + ui.MsgChannel <- msg if cb != nil { worker.Lock() diff --git a/worker/worker.go b/worker/worker.go index 2af892c4..bef5b727 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -9,12 +9,12 @@ import ( ) // Guesses the appropriate worker type based on the given source string -func NewWorker(source string) (*types.Worker, error) { +func NewWorker(source string, name string) (*types.Worker, error) { u, err := url.Parse(source) if err != nil { return nil, err } - worker := types.NewWorker() + worker := types.NewWorker(name) scheme := u.Scheme if strings.ContainsRune(scheme, '+') { scheme = scheme[:strings.IndexRune(scheme, '+')] |