Improve error handling for geocoderDataIterator

This commit is contained in:
Andrew Pendleton
2016-04-14 13:32:38 -04:00
parent d3845ea9f9
commit 4474634452
2 changed files with 12 additions and 5 deletions

View File

@@ -633,18 +633,24 @@ MBTiles.prototype.geocoderDataIterator = function(type) {
while (nextQueue.length && dataQueue.length) {
var nextCb = nextQueue.shift(), data, cbValue;
if (dataQueue[0] == doneSentinel) {
cbValue = {value: undefined, done: true};
cbValue = {
err: null,
row: {value: undefined, done: true}
}
} else {
data = dataQueue.shift();
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
// callback is executed
(function(nextCb, cbValue) {
setImmediate(function() {
nextCb(cbValue);
nextCb(cbValue.err, cbValue.row);
});
})(nextCb, cbValue);
}
@@ -657,7 +663,7 @@ MBTiles.prototype.geocoderDataIterator = function(type) {
refilling = true;
var segmentCount = 0;
_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;
sendIfAvailable();
}, function() {

View File

@@ -80,7 +80,8 @@ tape('putGeocoderData', function(assert) {
tape('geocoderDataIterator', function(assert) {
var it = to.geocoderDataIterator("term");
var data = [];
var n = function(item) {
var n = function(err, item) {
assert.ifError(err);
if (item.done) {
assert.equal(data.length, 2, "iterator produces two shards");