UNPKG

classy-pay-core

Version:

Shared tools used in ClassyPay-related projects

39 lines 1.39 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Config = void 0; require('source-map-support').install(); const Lock_1 = __importDefault(require("./utils/Lock")); const DataSourceManager_1 = __importDefault(require("./DataSourceManager")); class Config { constructor(dataSources) { this.dataSourceManagers = []; this.lock = new Lock_1.default(); for (const dataSource of dataSources) { // Allow data sources to call into config reentrant if needed this.dataSourceManagers.push(new DataSourceManager_1.default(dataSource, { get: key => this._getLocked(key) })); } } async get(key) { return await this.lock.lockForPath(async () => { return await this._getLocked(key); }); } async _getLocked(key) { for (const dataSourceManager of this.dataSourceManagers) { if (dataSourceManager.getQuerying()) { return null; } const value = await dataSourceManager.get(key); if (value) { return value; } } return null; } } exports.Config = Config; exports.default = Config; //# sourceMappingURL=Config.js.map