fix(classes): cleanup resources, add cancellable timeouts, and fix bugs in several core utility classes

This commit is contained in:
2026-03-01 19:21:42 +00:00
parent 597e9e15c3
commit ddf4e698c9
11 changed files with 197 additions and 35 deletions

View File

@@ -70,6 +70,8 @@ export class InterestMap<DTInterestId, DTInterestFullfillment> {
if (!returnInterest) {
returnInterest = newInterest;
this.interestObjectMap.add(returnInterest);
} else {
newInterest.destroy(); // clean up abandoned Interest's timers
}
this.interestObservable.push(returnInterest);
return returnInterest;
@@ -131,4 +133,16 @@ export class InterestMap<DTInterestId, DTInterestFullfillment> {
});
return interest; // if an interest is found, the interest is returned, otherwise interest is null
}
/**
* destroys the InterestMap and cleans up all resources
*/
public destroy() {
const interests = this.interestObjectMap.getArray();
for (const interest of interests) {
interest.destroy();
}
this.interestObjectMap.wipe();
this.interestObservable.signalComplete();
}
}