abort pending requests from previous rerouteAllSegments (empty queue)
This commit is contained in:
parent
9ec5985b2c
commit
59d4acc3c6
2 changed files with 20 additions and 2 deletions
|
|
@ -97,6 +97,11 @@
|
||||||
|
|
||||||
function updateRoute(evt) {
|
function updateRoute(evt) {
|
||||||
router.setOptions(evt.options);
|
router.setOptions(evt.options);
|
||||||
|
|
||||||
|
// abort pending requests from previous rerouteAllSegments
|
||||||
|
if (!router.queue.idle()) {
|
||||||
|
router.queue.kill();
|
||||||
|
}
|
||||||
routing.rerouteAllSegments(onUpdate);
|
routing.rerouteAllSegments(onUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -156,7 +161,9 @@
|
||||||
|
|
||||||
function onUpdate(err) {
|
function onUpdate(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
if (err !== L.BRouter.ABORTED_ERROR) {
|
||||||
BR.message.showError(err);
|
BR.message.showError(err);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
BR.message.hideError();
|
BR.message.hideError();
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,8 @@ L.BRouter = L.Class.extend({
|
||||||
URL_PROFILE_UPLOAD: BR.conf.host + '/brouter/profile',
|
URL_PROFILE_UPLOAD: BR.conf.host + '/brouter/profile',
|
||||||
PRECISION: 6,
|
PRECISION: 6,
|
||||||
NUMBER_SEPARATOR: ',',
|
NUMBER_SEPARATOR: ',',
|
||||||
GROUP_SEPARATOR: '|'
|
GROUP_SEPARATOR: '|',
|
||||||
|
ABORTED_ERROR: 'aborted'
|
||||||
},
|
},
|
||||||
|
|
||||||
options: {
|
options: {
|
||||||
|
|
@ -18,6 +19,16 @@ L.BRouter = L.Class.extend({
|
||||||
this.queue = async.queue(L.bind(function (task, callback) {
|
this.queue = async.queue(L.bind(function (task, callback) {
|
||||||
this.getRoute(task.segment, callback);
|
this.getRoute(task.segment, callback);
|
||||||
}, this), 1);
|
}, this), 1);
|
||||||
|
|
||||||
|
// patch to call callbacks on kill for cleanup (loadingTrailer)
|
||||||
|
this.queue.kill = function () {
|
||||||
|
var aborted = this.tasks;
|
||||||
|
this.drain = null;
|
||||||
|
this.tasks = [];
|
||||||
|
aborted.forEach(function(task) {
|
||||||
|
task.callback(L.BRouter.ABORTED_ERROR);
|
||||||
|
});
|
||||||
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
setOptions: function(options) {
|
setOptions: function(options) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue