Improve error handling for geocoderDataIterator
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user