rc-js-util
Version:
A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.
31 lines • 1.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CleanupRegistry = void 0;
const dirty_checked_unique_collection_js_1 = require("../collection/dirty-checked-unique-collection.js");
/**
* @public
* Strong reference implementation of {@link ICleanupRegistry}.
*/
class CleanupRegistry {
constructor() {
this.cleanupCallbacks = new dirty_checked_unique_collection_js_1.DirtyCheckedUniqueCollection();
}
executeCleanups() {
const cleanupCallbacks = this.cleanupCallbacks.getArray();
for (let i = 0, iEnd = cleanupCallbacks.length; i < iEnd; i++) {
cleanupCallbacks[i]();
}
this.cleanupCallbacks.clear();
}
registerCleanup(listener) {
this.cleanupCallbacks.add(listener);
}
unregisterCleanup(listener) {
this.cleanupCallbacks.delete(listener);
}
listCleanups() {
return this.cleanupCallbacks.getArray();
}
}
exports.CleanupRegistry = CleanupRegistry;
//# sourceMappingURL=cleanup-registry.js.map