Windshaft-cartodb/lib/models/mapconfig/adapter/index.js

32 lines
894 B
JavaScript
Raw Normal View History

2016-05-24 03:37:06 +08:00
'use strict';
2019-10-22 01:07:24 +08:00
function MapConfigAdapter (adapters) {
this.adapters = Array.isArray(adapters) ? adapters : Array.apply(null, arguments);
2016-05-24 03:37:06 +08:00
}
module.exports = MapConfigAdapter;
2019-10-22 01:07:24 +08:00
MapConfigAdapter.prototype.getMapConfig = function (user, requestMapConfig, params, context, callback) {
2016-05-24 03:37:06 +08:00
var self = this;
var i = 0;
var tasksLeft = this.adapters.length;
let mapConfigStats = {};
2019-10-22 01:07:24 +08:00
function next (err, _requestMapConfig, adapterStats = {}) {
2016-05-24 03:37:06 +08:00
if (err) {
return callback(err);
}
mapConfigStats = Object.assign(mapConfigStats, adapterStats);
2016-05-24 03:37:06 +08:00
if (tasksLeft-- === 0) {
return callback(null, _requestMapConfig, mapConfigStats);
2016-05-24 03:37:06 +08:00
}
var nextAdapter = self.adapters[i++];
nextAdapter.getMapConfig(user, _requestMapConfig, params, context, next);
}
next(null, requestMapConfig, mapConfigStats);
2016-05-24 03:37:06 +08:00
};