WIP: race conditions and stalling server
This commit is contained in:
committed by
Patrick Niklaus
parent
8ac403abb9
commit
8947c789a9
@@ -47,12 +47,12 @@ module.exports = function () {
|
||||
|
||||
if (headers.has('route')) {
|
||||
if (json.matchings.length != 1) throw new Error('*** Checking route only supported for matchings with one subtrace');
|
||||
route = this.wayList(json.matchings[0].instructions);
|
||||
route = this.wayList(json.matchings[0]);
|
||||
}
|
||||
|
||||
if (headers.has('duration')) {
|
||||
if (json.matchings.length != 1) throw new Error('*** Checking duration only supported for matchings with one subtrace');
|
||||
duration = json.matchings[0].route_summary.total_time;
|
||||
duration = json.matchings[0].duration;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,13 +66,13 @@ module.exports = function () {
|
||||
|
||||
r.query = this.query;
|
||||
r.json = JSON.parse(body);
|
||||
r.status = r.json.status === 200 ? 'x' : null;
|
||||
r.status = res.statusCode === 200 ? 'x' : null;
|
||||
if (r.status) {
|
||||
r.route = this.wayList(r.json.route_instructions);
|
||||
r.route = this.wayList(r.json.routes[0]);
|
||||
|
||||
if (r.route === util.format('w%d', i)) {
|
||||
r.time = r.json.route_summary.total_time;
|
||||
r.distance = r.json.route_summary.total_distance;
|
||||
r.time = r.json.routes[0].duration;
|
||||
r.distance = r.json.routes[0].distance;
|
||||
r.speed = r.time > 0 ? parseInt(3.6 * r.distance / r.time) : null;
|
||||
} else {
|
||||
r.status = null;
|
||||
@@ -96,15 +96,23 @@ module.exports = function () {
|
||||
});
|
||||
|
||||
result.bothw = {};
|
||||
['status', 'time', 'distance', 'speed'].forEach((key) => {
|
||||
|
||||
var sq = d3.queue();
|
||||
|
||||
var parseRes = (key, scb) => {
|
||||
if (result.forw[key] === result.backw[key]) {
|
||||
result.bothw[key] = result.forw[key];
|
||||
} else {
|
||||
result.bothw[key] = 'diff';
|
||||
}
|
||||
scb();
|
||||
}
|
||||
|
||||
['status', 'time', 'distance', 'speed'].forEach((key) => {
|
||||
sq.defer(parseRes, key);
|
||||
});
|
||||
|
||||
cb(null, result);
|
||||
sq.awaitAll(() => { cb(null, result); });
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user