G A-38: HeldWriter.Held answers the findings it holds
Builds: design 47 G A-38, A-29
This commit is contained in:
@@ -98,3 +98,15 @@ func (h *HeldWriter[F, C, S, A]) WriteWire(ctx context.Context, finding map[stri
|
||||
}
|
||||
return h.Write(ctx, f)
|
||||
}
|
||||
|
||||
// Held answers the findings the writer holds, a copy taken under its lock (design 47 G A-38), so a part reads its open findings
|
||||
// from the writer.
|
||||
func (h *HeldWriter[F, C, S, A]) Held() []F {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
out := make([]F, 0, len(h.held))
|
||||
for _, f := range h.held {
|
||||
out = append(out, f)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -514,6 +514,11 @@ func subHeldWriterStatesWhatItHoldsFromItsOwnState(t *testing.T) {
|
||||
len(stated.Findings) != 2 || stated.Asked != "a1" {
|
||||
t.Fatalf("the statement says %+v after %d events", stated, len(sent))
|
||||
}
|
||||
if held := h.Held(); len(held) != 2 {
|
||||
t.Fatalf("Held answers %v", held)
|
||||
} else if held[0].ID = "mutated"; len(h.Held()) != 2 {
|
||||
t.Fatal("Held is not a copy")
|
||||
}
|
||||
ids := []string{stated.Findings[0].ID, stated.Findings[1].ID}
|
||||
slices.Sort(ids)
|
||||
if ids[0] != "raised" || ids[1] != "wired" {
|
||||
|
||||
Reference in New Issue
Block a user