furkot-directions
Advanced tools
Comparing version 0.0.12 to 0.0.13
0.0.13 / 2017-01-14 | ||
=================== | ||
* use the same limiter for all Google requests | ||
* simplify unwiding outstanding requests upon abort | ||
* skip limiter interval when not executing a request because query has been aborted | ||
* limiter-component 0.2.1 -> 1.0.0 | ||
0.0.12 / 2017-01-13 | ||
@@ -3,0 +11,0 @@ =================== |
@@ -98,2 +98,3 @@ var _defaults = require('lodash.defaults'); | ||
name: service.name, | ||
limiter: options[(service.name + '_limiter')], | ||
enable: options[(service.name + '_enable')], | ||
@@ -100,0 +101,0 @@ skip: service.skip |
@@ -47,19 +47,11 @@ var _defaults = require('lodash.defaults'); | ||
} | ||
if (outstanding[queryId].subquery) { | ||
return options.abort(outstanding[queryId].subquery); | ||
// cancel later request if scheduled | ||
if (outstanding[queryId].laterTimeoutId) { | ||
clearTimeout(outstanding[queryId].laterTimeoutId); | ||
} | ||
if (outstanding[queryId].query) { | ||
return options.abort(outstanding[queryId].query); | ||
// cancel request in progress | ||
if (outstanding[queryId].reqInProgress) { | ||
outstanding[queryId].reqInProgress.abort(); | ||
} | ||
if (outstanding[queryId]) { | ||
// cancel later request if scheduled | ||
if (outstanding[queryId].laterTimeoutId) { | ||
clearTimeout(outstanding[queryId].laterTimeoutId); | ||
} | ||
// cancel request in progress | ||
if (outstanding[queryId].reqInProgress) { | ||
outstanding[queryId].reqInProgress.abort(); | ||
} | ||
outstanding[queryId].callback('aborted'); | ||
} | ||
outstanding[queryId].callback(ERROR); | ||
} | ||
@@ -107,3 +99,2 @@ | ||
if (segments !== query) { | ||
outstanding[queryId].query = queryId + 'q'; | ||
return directions(outstanding[queryId].query, segments, | ||
@@ -127,2 +118,3 @@ new Array(segments.length), function (err, stop, id, query, result) { | ||
// query has been aborted | ||
limiter.skip(); // immediately process the next request in the queue | ||
return; | ||
@@ -160,3 +152,2 @@ } | ||
outstanding[queryId].subquery = queryId + 's'; | ||
return directions(outstanding[queryId].subquery, query, | ||
@@ -186,3 +177,9 @@ new Array(1), function (err, stop, id, query, result) { | ||
outstanding[queryId] = {}; | ||
outstanding[queryId] = outstanding[queryId] || { | ||
stack: 0 | ||
}; | ||
outstanding[queryId].stack += 1; | ||
outstanding[queryId].callback = function (err) { | ||
fn(err, true); | ||
}; | ||
queryArray.delta = 0; | ||
@@ -192,5 +189,8 @@ | ||
if (outstanding[queryId]) { | ||
delete outstanding[queryId]; | ||
outstanding[queryId].stack -= 1; | ||
if (!outstanding[queryId].stack) { | ||
delete outstanding[queryId]; | ||
} | ||
if (err === ERROR) { | ||
return fn(undefined, true); | ||
return fn(outstanding[queryId] ? err : undefined, true); | ||
} | ||
@@ -205,2 +205,3 @@ fn(err, false, queryId, queryArray, result); | ||
penaltyInterval: 2000, | ||
limiter: limiters[options.name], | ||
request: request, | ||
@@ -210,3 +211,3 @@ abort: abort | ||
options.url = initUrl(options.url); | ||
limiters[options.name] = limiters[options.name] || require('./limiter')(options.interval, options.penaltyInterval); | ||
limiters[options.name] = options.limiter || require('limiter-component')(options.interval, options.penaltyInterval); | ||
limiter = limiters[options.name]; | ||
@@ -213,0 +214,0 @@ simplify = require('./simplify')(options); |
{ | ||
"name": "furkot-directions", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "Directions service for Furkot", | ||
@@ -23,3 +23,3 @@ "author": { | ||
"geodesy": "^1.1.1", | ||
"limiter-component": "^0.2.1", | ||
"limiter-component": "^1.0.0", | ||
"lodash.defaults": "^4.2.0", | ||
@@ -26,0 +26,0 @@ "run-series": "^1.1.4", |
Sorry, the diff of this file is not supported yet
85864
26
1334
+ Addedlimiter-component@1.2.0(transitive)
- Removedlimiter-component@0.2.2(transitive)
Updatedlimiter-component@^1.0.0