1
0
forked from rosa/hakurei

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