aboutsummaryrefslogtreecommitdiffstats
path: root/lib/msgstore.go
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2023-06-20 11:07:07 -0500
committerRobin Jarry <robin@jarry.cc>2023-06-20 23:16:25 +0200
commit115fb9322ce4065bb7212e8979464d0f9c1db12d (patch)
treef52beba3d78440a46f97324214cd61e853996ec9 /lib/msgstore.go
parent982ee4128c584759e518b6d541ca01cce6c5d547 (diff)
downloadaerc-115fb9322ce4065bb7212e8979464d0f9c1db12d.tar.gz
worker: add context to cancellable requests
Add a Context field to requests which we may want to cancel when changing directories. Add a Cancelled meta-message to inform the UI that a request was cancelled (as opposed to Done or Error). Delete callbacks when a request is Cancelled. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Tested-by: Bence Ferdinandy <bence@ferdinandy.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/msgstore.go')
-rw-r--r--lib/msgstore.go30
1 files changed, 19 insertions, 11 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go
index f7ffaa51..77aeb4c1 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -139,16 +139,20 @@ func (store *MessageStore) FetchHeaders(uids []uint32,
}
}
if len(toFetch) > 0 {
- store.worker.PostAction(&types.FetchMessageHeaders{Uids: toFetch}, func(msg types.WorkerMessage) {
- if _, ok := msg.(*types.Error); ok {
- for _, uid := range toFetch {
- delete(store.pendingHeaders, uid)
+ store.worker.PostAction(&types.FetchMessageHeaders{
+ Context: store.ctx,
+ Uids: toFetch,
+ },
+ func(msg types.WorkerMessage) {
+ if _, ok := msg.(*types.Error); ok {
+ for _, uid := range toFetch {
+ delete(store.pendingHeaders, uid)
+ }
}
- }
- if cb != nil {
- cb(msg)
- }
- })
+ if cb != nil {
+ cb(msg)
+ }
+ })
}
}
@@ -664,7 +668,8 @@ func (store *MessageStore) Prev() {
func (store *MessageStore) Search(args []string, cb func([]uint32)) {
store.worker.PostAction(&types.SearchDirectory{
- Argv: args,
+ Context: store.ctx,
+ Argv: args,
}, func(msg types.WorkerMessage) {
if msg, ok := msg.(*types.SearchResults); ok {
allowedUids := store.Uids()
@@ -776,11 +781,13 @@ func (store *MessageStore) Sort(criteria []*types.SortCriterion, cb func(types.W
if store.threadedView && !store.buildThreads {
store.worker.PostAction(&types.FetchDirectoryThreaded{
+ Context: store.ctx,
SortCriteria: criteria,
FilterCriteria: store.filter,
}, handle_return)
} else {
store.worker.PostAction(&types.FetchDirectoryContents{
+ Context: store.ctx,
SortCriteria: criteria,
FilterCriteria: store.filter,
}, handle_return)
@@ -830,7 +837,8 @@ func (store *MessageStore) fetchFlags() {
store.fetchFlagsDebounce = time.AfterFunc(store.fetchFlagsDelay, func() {
store.Lock()
store.worker.PostAction(&types.FetchMessageFlags{
- Uids: store.needsFlags,
+ Context: store.ctx,
+ Uids: store.needsFlags,
}, nil)
store.needsFlags = []uint32{}
store.Unlock()