fix(classes): cleanup resources, add cancellable timeouts, and fix bugs in several core utility classes
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user