diff --git a/lib/cartodb/backends/layer-stats/mapnik-layer-stats.js b/lib/cartodb/backends/layer-stats/mapnik-layer-stats.js index 1f7fce76..b590f979 100644 --- a/lib/cartodb/backends/layer-stats/mapnik-layer-stats.js +++ b/lib/cartodb/backends/layer-stats/mapnik-layer-stats.js @@ -235,7 +235,10 @@ function (layer, dbConnection, callback) { // to define the queries of the second phase queries.phase(() => firstPhaseQueries(queries, context)); queries.phase(() => secondPhaseQueries(queries, context)); - queries.run(results => callback(null, results)).catch(error => callback(error)); + queries.run() + .then(results => callback(null, results)) + .catch(error => callback(error)); + }; module.exports = MapnikLayerStats; diff --git a/lib/cartodb/utils/phased-execution.js b/lib/cartodb/utils/phased-execution.js index c9ac445d..46dfbb39 100644 --- a/lib/cartodb/utils/phased-execution.js +++ b/lib/cartodb/utils/phased-execution.js @@ -65,7 +65,7 @@ * })); * }); * // Execute all tasks - * p.run((results) => { + * p.run().then((results) => { * console.log("RESULTS:", results); * }).catch((err) => { * console.log("ERROR:", error); @@ -82,14 +82,13 @@ module.exports = class PhasedExecution { task(promise) { this.tasks.push(promise); } - run(callback) { + run() { this.tasks = []; let phase = this.phases.shift(); if (phase) { phase(this); - return Promise.all(this.tasks) - .then(() => this.run()) - .then(() => { if (callback) { callback(this.results); } }); + return Promise.all(this.tasks).then(() => this.run()); } + return this.results; } };