pull-level
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -17,3 +17,6 @@ var pull = require('pull-stream') | ||
var l = pushable() | ||
var l = pushable(function (err) { | ||
if(opts.onAbort) opts.onAbort(err) | ||
cleanup() | ||
}) | ||
@@ -29,3 +32,3 @@ var cleanup = post(db, opts, function (ch) { | ||
return pull(l, pull.through(null, cleanup)) | ||
return l | ||
@@ -32,0 +35,0 @@ } |
{ | ||
"name": "pull-level", | ||
"description": "pull-stream interface to levelup", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"homepage": "https://github.com/dominictarr/pull-level", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -55,2 +55,3 @@ var pull = require('pull-stream') | ||
var all = [] | ||
ended = false | ||
pull( | ||
@@ -69,3 +70,5 @@ pull.infinite(), | ||
l.write(db, function (err) { | ||
cb(err, all) | ||
if(ended) throw new Error('ended twice') | ||
ended = true | ||
cb(err, all) | ||
}) | ||
@@ -76,7 +79,10 @@ ) | ||
exports.exactly = function (n) { | ||
exports.exactly = function (n, err) { | ||
return function (read) { | ||
return function (abort, cb) { | ||
if(0 <=--n) read(abort, cb) | ||
else cb(true) | ||
else console.log(abort, err, true), read(abort || err || true, function (end, data) { | ||
console.log('ABORTED', end, data) | ||
cb(end, data) | ||
}) | ||
} | ||
@@ -83,0 +89,0 @@ } |
@@ -14,3 +14,3 @@ | ||
tape('live', function (t) { | ||
return t.end() | ||
var path = '/tmp/pull-level-read-live' | ||
@@ -69,2 +69,4 @@ require('rimraf').sync(path) | ||
var n = 2 | ||
h.timestamps(db, 10, function (err, all) { | ||
@@ -80,16 +82,8 @@ | ||
h.exactly(20), | ||
pull.collect(function (err, ary) { | ||
process.nextTick(function () { | ||
t.notOk(err) | ||
t.ok(second) | ||
console.log(ary) | ||
t.equal(ary.length, 20) | ||
t.equal(ary.length, all.length) | ||
var values = all.map(function (e) { return e.value }) | ||
t.deepEqual(ary, values) | ||
t.ok(sync) | ||
t.end() | ||
}) | ||
pull.collect(function (err, _ary) { | ||
t.notOk(err) | ||
ary = _ary | ||
console.log('END1') | ||
if(--n) return | ||
end() | ||
}) | ||
@@ -101,11 +95,26 @@ ) | ||
h.timestamps(db, 10, function (err, _all) { | ||
second = true | ||
t.notOk(err) | ||
all = all.concat(_all) | ||
// console.log('all', all, all.length) | ||
console.log('END2') | ||
if(--n) return | ||
end() | ||
}) | ||
}, 100) | ||
function end () { | ||
console.log('END') | ||
t.equal(ary.length, 20) | ||
t.equal(ary.length, all.length) | ||
var values = all.map(function (e) { return e.value }) | ||
t.deepEqual(ary, values) | ||
t.ok(sync) | ||
t.end() | ||
} | ||
}) | ||
}) | ||
return | ||
tape('live, sync:true', function (t) { | ||
@@ -116,3 +125,3 @@ var path = '/tmp/pull-level-read-live3' | ||
var second = false | ||
var second = false, ary | ||
@@ -130,6 +139,14 @@ h.timestamps(db, 10, function (err, all) { | ||
h.exactly(20), | ||
pull.collect(function (err, ary) { | ||
process.nextTick(function () { | ||
t.notOk(err) | ||
t.ok(second) | ||
pull.collect(function (err, _ary) { | ||
t.notOk(err) | ||
t.notOk(second) | ||
ary = _ary | ||
}) | ||
) | ||
setTimeout(function () { | ||
h.timestamps(db, 10, function (err, _all) { | ||
second = true | ||
all = all.concat(_all) | ||
console.log(ary) | ||
@@ -144,13 +161,3 @@ t.equal(ary.length, 20) | ||
t.end() | ||
}) | ||
}) | ||
) | ||
setTimeout(function () { | ||
h.timestamps(db, 10, function (err, _all) { | ||
second = true | ||
all = all.concat(_all) | ||
// console.log('all', all, all.length) | ||
}) | ||
}, 100) | ||
@@ -157,0 +164,0 @@ }) |
@@ -17,25 +17,29 @@ | ||
var second = false, sync | ||
var second = false, sync, ary, err = new Error('intentional') | ||
h.random(db, 10, function (err, all) { | ||
var n = 3 | ||
h.random(db, 10, function (err2, all) { | ||
if(err2) throw err2 | ||
pull( | ||
l.read(db, {live: true, onSync: function () { | ||
console.log('sync') | ||
sync = true | ||
}}), | ||
h.exactly(20), | ||
console.log('sync') | ||
sync = true | ||
}, onAbort: function (end) { | ||
t.ok(end) | ||
if(--n) return | ||
end() | ||
} | ||
}), | ||
h.exactly(20, err), | ||
pull.map(function (e) { | ||
return {key: e.key, value: e.value}//drop 'type' from live updates | ||
}), | ||
pull.collect(function (err, ary) { | ||
t.notOk(err) | ||
t.ok(second) | ||
console.log(ary) | ||
console.log(all) | ||
console.log(ary.length, all.length) | ||
t.equal(ary.length, all.length) | ||
t.deepEqual(h.sort(ary), all) | ||
t.ok(sync) | ||
t.end() | ||
pull.collect(function (err, _ary) { | ||
t.ok(err) | ||
ary = _ary | ||
if(--n) return | ||
end() | ||
}) | ||
@@ -45,6 +49,18 @@ ) | ||
h.random(db, 10, function (err, _all) { | ||
second = true | ||
all = h.sort(all.concat(_all)) | ||
}) | ||
if(--n) return | ||
end() | ||
}) | ||
function end() { | ||
console.log(ary) | ||
console.log(all) | ||
console.log(ary.length, all.length) | ||
t.deepEqual(h.sort(ary), all) | ||
t.equal(ary.length, all.length) | ||
t.ok(sync) | ||
t.end() | ||
} | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15177
398