Slightly more elegant results of queries

This commit is contained in:
Javier Goizueta
2018-05-08 20:41:42 +02:00
parent 741bcd1a80
commit eea7bed2f3
2 changed files with 8 additions and 6 deletions
@@ -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;
+4 -5
View File
@@ -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;
}
};