pull-stream
Advanced tools
Comparing version 2.28.1 to 2.28.2
{ | ||
"name": "pull-stream", | ||
"description": "minimal pull stream", | ||
"version": "2.28.1", | ||
"version": "2.28.2", | ||
"homepage": "https://github.com/dominictarr/pull-stream", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -84,1 +84,38 @@ var pull = require('../') | ||
}) | ||
test("take doesn't abort until the last read", function (t) { | ||
var aborted = false | ||
var ary = [1,2,3,4,5], i = 0 | ||
var read = pull( | ||
function (abort, cb) { | ||
if(abort) cb(aborted = true) | ||
else if(i > ary.length) cb(true) | ||
else cb(null, ary[i++]) | ||
}, | ||
pull.take(function (d) { | ||
return d < 3 | ||
}, {last: true}) | ||
) | ||
read(null, function (_, d) { | ||
t.notOk(aborted, "hasn't aborted yet") | ||
read(null, function (_, d) { | ||
t.notOk(aborted, "hasn't aborted yet") | ||
read(null, function (_, d) { | ||
t.notOk(aborted, "hasn't aborted yet") | ||
read(null, function (end, d) { | ||
t.ok(end, 'stream ended') | ||
t.equal(d, undefined, 'data undefined') | ||
t.ok(aborted, "has aborted by now") | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
@@ -143,18 +143,25 @@ var u = require('pull-core') | ||
return function (end, cb) { | ||
if(ended) return cb(ended) | ||
if(ended = end) return read(ended, cb) | ||
read(null, function (end, data) { | ||
if(ended = ended || end) return cb(ended) | ||
if(!test(data)) { | ||
ended = true | ||
read(true, function () { | ||
last ? cb(end, data) : cb(true) | ||
}) | ||
} | ||
else | ||
cb(null, data) | ||
function terminate (cb) { | ||
read(true, function (err) { | ||
last = false; cb(err || true) | ||
}) | ||
} | ||
return function (end, cb) { | ||
if(ended) last ? terminate(cb) : cb(ended) | ||
else if(ended = end) read(ended, cb) | ||
else | ||
read(null, function (end, data) { | ||
if(ended = ended || end) { | ||
//last ? terminate(cb) : | ||
cb(ended) | ||
} | ||
else if(!test(data)) { | ||
ended = true | ||
last ? cb(null, data) : terminate(cb) | ||
} | ||
else | ||
cb(null, data) | ||
}) | ||
} | ||
} | ||
@@ -161,0 +168,0 @@ |
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
53096
1552