Improve error handling for geocoderDataIterator
This commit is contained in:
@@ -633,18 +633,24 @@ MBTiles.prototype.geocoderDataIterator = function(type) {
|
|||||||
while (nextQueue.length && dataQueue.length) {
|
while (nextQueue.length && dataQueue.length) {
|
||||||
var nextCb = nextQueue.shift(), data, cbValue;
|
var nextCb = nextQueue.shift(), data, cbValue;
|
||||||
if (dataQueue[0] == doneSentinel) {
|
if (dataQueue[0] == doneSentinel) {
|
||||||
cbValue = {value: undefined, done: true};
|
cbValue = {
|
||||||
|
err: null,
|
||||||
|
row: {value: undefined, done: true}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
data = dataQueue.shift();
|
data = dataQueue.shift();
|
||||||
maybeRefillBuffer();
|
maybeRefillBuffer();
|
||||||
|
|
||||||
cbValue = {value: {shard: data.shard, data: zlib.inflateSync(data.data)}, done: false};
|
cbValue = {
|
||||||
|
err: data.err,
|
||||||
|
row: {value: {shard: data.row.shard, data: zlib.inflateSync(data.row.data)}, done: false}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
// bind the callback and data now so that they don't change before the setImmediate
|
// bind the callback and data now so that they don't change before the setImmediate
|
||||||
// callback is executed
|
// callback is executed
|
||||||
(function(nextCb, cbValue) {
|
(function(nextCb, cbValue) {
|
||||||
setImmediate(function() {
|
setImmediate(function() {
|
||||||
nextCb(cbValue);
|
nextCb(cbValue.err, cbValue.row);
|
||||||
});
|
});
|
||||||
})(nextCb, cbValue);
|
})(nextCb, cbValue);
|
||||||
}
|
}
|
||||||
@@ -657,7 +663,7 @@ MBTiles.prototype.geocoderDataIterator = function(type) {
|
|||||||
refilling = true;
|
refilling = true;
|
||||||
var segmentCount = 0;
|
var segmentCount = 0;
|
||||||
_this._db.each('SELECT shard, data FROM geocoder_data WHERE type = ? ORDER BY shard limit ?,?', type, position, chunkSize, function(err, row) {
|
_this._db.each('SELECT shard, data FROM geocoder_data WHERE type = ? ORDER BY shard limit ?,?', type, position, chunkSize, function(err, row) {
|
||||||
dataQueue.push(row);
|
dataQueue.push({row: row, err: err});
|
||||||
segmentCount += 1;
|
segmentCount += 1;
|
||||||
sendIfAvailable();
|
sendIfAvailable();
|
||||||
}, function() {
|
}, function() {
|
||||||
|
|||||||
@@ -80,7 +80,8 @@ tape('putGeocoderData', function(assert) {
|
|||||||
tape('geocoderDataIterator', function(assert) {
|
tape('geocoderDataIterator', function(assert) {
|
||||||
var it = to.geocoderDataIterator("term");
|
var it = to.geocoderDataIterator("term");
|
||||||
var data = [];
|
var data = [];
|
||||||
var n = function(item) {
|
var n = function(err, item) {
|
||||||
|
assert.ifError(err);
|
||||||
if (item.done) {
|
if (item.done) {
|
||||||
assert.equal(data.length, 2, "iterator produces two shards");
|
assert.equal(data.length, 2, "iterator produces two shards");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user