UNPKG

@imqueue/core

Version:

Simple JSON-based messaging queue for inter service communication

28 lines 961 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ClusterManager = void 0; const uuid_1 = require("./uuid"); class ClusterManager { constructor() { this.clusters = []; } init(cluster) { const initializedCluster = Object.assign(cluster, { id: (0, uuid_1.uuid)() }); this.clusters.push(initializedCluster); return initializedCluster; } async anyCluster(fn) { await Promise.all(this.clusters.map(cluster => fn(cluster))); } async remove(cluster, destroy = true) { const id = typeof cluster === 'string' ? cluster : cluster.id; this.clusters = this.clusters.filter(cluster => cluster.id !== id); if (this.clusters.length === 0 && destroy && typeof this.destroy === 'function') { await this.destroy(); } } } exports.ClusterManager = ClusterManager; //# sourceMappingURL=ClusterManager.js.map