'use strict'; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Licensed Materials - Property of IBM * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2019 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['../../../lib/@waca/dashboard-common/dist/core/APIFactory'], function (APIFactory) { 'use strict'; var MetadataLoader = function () { /* The MetadataLoader will improve performance by starting to load metadata as soon as possible in the dashboard life cycle The feature will also prevent hogging all network connections by leveraging a queue which only allows up to 3 metadata requests at once */ function MetadataLoader(options) { _classCallCheck(this, MetadataLoader); this.options = options; this.API = options.features.API; } MetadataLoader.prototype.initialize = function initialize() { var dataSources = this.API.getFeature('DataSources').getDataSourceList(); this.loadMetadata(dataSources); }; MetadataLoader.prototype.getAPI = function getAPI() { return APIFactory.createAPI(this, []); }; MetadataLoader.prototype.loadMetadata = function loadMetadata(dataSources) { var loaderPromises = []; dataSources.forEach(function (dataSource) { return loaderPromises.push(dataSource.loadMetadata); }); var MAX_WORKERS = 3; //Avoid hogging all network connections by only allowing up to 3 concurrent metadata requests var promiseResults = []; var workerCount = 0; var promiseIdx = 0; return new Promise(function (done) { var getNextLoaderPromise = function getNextLoaderPromise() { if (workerCount < MAX_WORKERS && promiseIdx < loaderPromises.length) { loaderPromises[promiseIdx]().then(onSettlePromise).fail(onSettlePromise); promiseIdx++; workerCount++; getNextLoaderPromise(); } else if (workerCount === 0 && promiseIdx === loaderPromises.length) { done(promiseResults); } }; var onSettlePromise = function onSettlePromise(result) { promiseResults.push(result); workerCount--; getNextLoaderPromise(); }; getNextLoaderPromise(); }); }; return MetadataLoader; }(); return MetadataLoader; }); //# sourceMappingURL=MetadataLoader.js.map