internal/pkg: pending error alongside done channel

This significantly simplifies synchronisation of access to identErr.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-04-18 03:10:37 +09:00
parent 9e18de1dc2
commit 27b1aaae38

View File

@@ -560,6 +560,8 @@ func newToplevel(ctx context.Context) *toplevel {
type pendingCure struct {
// Closed on cure completion.
done <-chan struct{}
// Error outcome, safe to access after done is closed.
err error
// Cancels the corresponding cure.
cancel context.CancelFunc
}
@@ -1065,7 +1067,7 @@ func (c *Cache) loadOrStoreIdent(id unique.Handle[ID]) (
<-pending.done
c.identMu.RLock()
if checksum, ok = c.ident[id]; !ok {
err = c.identErr[id]
err = pending.err
}
c.identMu.RUnlock()
return
@@ -1091,6 +1093,7 @@ func (c *Cache) finaliseIdent(
) {
c.identMu.Lock()
if err != nil {
c.identPending[id].err = err
c.identErr[id] = err
} else {
c.ident[id] = checksum