Repair error caused by mutation of a set mid-iteration

This commit is contained in:
Tony Garnock-Jones 2021-01-29 15:37:27 +01:00
parent a64a8177eb
commit 5d2e776ecf
1 changed files with 7 additions and 2 deletions

View File

@ -75,6 +75,12 @@ export class Graph<SubjectId, ObjectId> {
subjectObjects.forEach((oid: ObjectId) => MapSet.del(this.edgesForward, oid, subjectId));
}
observersOf(objectId: ObjectId): Array<SubjectId> {
const subjects = this.edgesForward.get(objectId);
if (subjects === void 0) return [];
return Array.from(subjects);
}
repairDamage(repairNode: (subjectId: SubjectId) => void) {
let repairedThisRound = new FlexSet(this.objectIdCanonicalizer);
while (true) {
@ -92,8 +98,7 @@ export class Graph<SubjectId, ObjectId> {
if (workSet.size === 0) break;
workSet.forEach(objectId => {
const subjects = this.edgesForward.get(objectId) ?? [] as Array<SubjectId>;
subjects.forEach((subjectId: SubjectId) => {
this.observersOf(objectId).forEach((subjectId: SubjectId) => {
this.forgetSubject(subjectId);
this.withSubject(subjectId, () => repairNode(subjectId));
});