'use strict'; var Pool = require('./Pool.js'); "use strict"; class PoolGroupClass { constructor() { /** * A map to store the pools by their class type. * @private */ this._poolsByClass = /* @__PURE__ */ new Map(); } /** * Prepopulates a specific pool with a given number of items. * @template T The type of items in the pool. Must extend PoolItem. * @param {PoolItemConstructor} Class - The constructor of the items in the pool. * @param {number} total - The number of items to add to the pool. */ prepopulate(Class, total) { const classPool = this.getPool(Class); classPool.prepopulate(total); } /** * Gets an item from a specific pool. * @template T The type of items in the pool. Must extend PoolItem. * @param {PoolItemConstructor} Class - The constructor of the items in the pool. * @param {unknown} [data] - Optional data to pass to the item's constructor. * @returns {T} The item from the pool. */ get(Class, data) { const pool = this.getPool(Class); return pool.get(data); } /** * Returns an item to its respective pool. * @param {PoolItem} item - The item to return to the pool. */ return(item) { const pool = this.getPool(item.constructor); pool.return(item); } /** * Gets a specific pool based on the class type. * @template T The type of items in the pool. Must extend PoolItem. * @param {PoolItemConstructor} ClassType - The constructor of the items in the pool. * @returns {Pool} The pool of the given class type. */ getPool(ClassType) { if (!this._poolsByClass.has(ClassType)) { this._poolsByClass.set(ClassType, new Pool.Pool(ClassType)); } return this._poolsByClass.get(ClassType); } /** gets the usage stats of each pool in the system */ stats() { const stats = {}; this._poolsByClass.forEach((pool) => { const name = stats[pool._classType.name] ? pool._classType.name + pool._classType.ID : pool._classType.name; stats[name] = { free: pool.totalFree, used: pool.totalUsed, size: pool.totalSize }; }); return stats; } } const BigPool = new PoolGroupClass(); exports.BigPool = BigPool; exports.PoolGroupClass = PoolGroupClass; //# sourceMappingURL=PoolGroup.js.map