db: fix level-js iterators.

This commit is contained in:
Christopher Jeffrey 2016-08-27 15:19:51 -07:00
parent a143c78369
commit 2d61a43fba
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -105,11 +105,18 @@ function Iterator(db, options) {
options.keyAsBuffer = false;
this.db = db;
this.iter = db.level.iterator(options);
this._end = false;
}
Iterator.prototype.next = function(callback) {
var self = this;
this.iter.next(function(err, key, value) {
// Hack for level-js: it doesn't actually
// end iterators -- it keeps streaming keys
// and values.
if (self._end)
return;
if (err) {
callback(err);
return;
@ -137,6 +144,7 @@ Iterator.prototype.seek = function seek(key) {
};
Iterator.prototype.end = function end(callback) {
this._end = true;
this.iter.end(callback);
};