2016-05-24 03:37:06 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function MapConfigAdapter (adapters) {
|
2016-05-26 17:23:19 +08:00
|
|
|
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;
|
|
|
|
|
2018-09-04 21:13:17 +08:00
|
|
|
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);
|
|
|
|
}
|
2018-09-04 21:13:17 +08:00
|
|
|
|
|
|
|
mapConfigStats = Object.assign(mapConfigStats, adapterStats);
|
|
|
|
|
2016-05-24 03:37:06 +08:00
|
|
|
if (tasksLeft-- === 0) {
|
2018-09-04 21:13:17 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-09-04 21:13:17 +08:00
|
|
|
next(null, requestMapConfig, mapConfigStats);
|
2016-05-24 03:37:06 +08:00
|
|
|
};
|