UNPKG

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.

44 lines 1.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReferenceCountedNode = void 0; const broadcast_channel_js_1 = require("../eventing/broadcast-channel.js"); const managed_resource_links_js_1 = require("./managed-resource-links.js"); const _debug_js_1 = require("../debug/_debug.js"); /** * @internal */ class ReferenceCountedNode { constructor() { this.onFreeChannel = new broadcast_channel_js_1.BroadcastChannel("onFree"); this.linkedReferences = null; this.references = 1; } onClaimed() { if (this.references <= 0) { _BUILD.DEBUG && _debug_js_1._Debug.error("object has been released already"); return; } ++this.references; } onReleased() { if (--this.references === 0) { this.onFree(); } } getIsDestroyed() { return this.references <= 0; } getLinked() { if (this.linkedReferences == null) { return this.linkedReferences = new managed_resource_links_js_1.ManagedResourceLinks(this); } return this.linkedReferences; } onFree() { var _a; (_a = this.linkedReferences) === null || _a === void 0 ? void 0 : _a.unlinkAll(); this.onFreeChannel.emit(); } } exports.ReferenceCountedNode = ReferenceCountedNode; //# sourceMappingURL=reference-counted-node.js.map