Comparing version 1.0.2 to 1.1.0
39
index.js
@@ -14,5 +14,10 @@ //another idea: buffer 2* the max, but only call write with half of that, | ||
reduce = reduce || append | ||
var ended | ||
return function (read) { | ||
var ended, _cb, _read | ||
function reader (read) { | ||
var queue = null, writing = false, length = 0 | ||
_read = read | ||
if(ended) return read(ended, function (err) { | ||
cb(err) | ||
_cb && _cb() | ||
}) | ||
@@ -27,3 +32,6 @@ function flush () { | ||
if(ended === true && !length) cb(err) | ||
else if(ended && ended !== true) cb(err || ended) | ||
else if(ended && ended !== true) { | ||
cb(ended) | ||
_cb && _cb() | ||
} | ||
else if(err) read(ended = err, cb) //abort upstream. | ||
@@ -34,2 +42,3 @@ else if(length) flush() | ||
} | ||
function next (end, data) { | ||
@@ -46,6 +55,28 @@ if(ended) return | ||
} | ||
reader.abort = function (__cb) { | ||
_cb = function (end) { | ||
__cb && __cb() | ||
} | ||
read(ended = new Error('aborted'), function (end) { | ||
end = end === true ? null : end | ||
if(!writing) { | ||
cb && cb(end) | ||
_cb && _cb(end) | ||
} | ||
}) | ||
} | ||
read(null, next) | ||
} | ||
reader.abort = function (cb) { | ||
ended = new Error('aborted before connecting') | ||
_cb = function (err) { | ||
cb && cb() | ||
} | ||
} | ||
return reader | ||
} | ||
{ | ||
"name": "pull-write", | ||
"description": "", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"homepage": "https://github.com/dominictarr/pull-write", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -139,2 +139,56 @@ var tape = require('tape') | ||
tape('abort', function (t) { | ||
t.plan(2) | ||
var output = [], writer = createWrite(function write(data, cb) { | ||
if(data == null) throw new Error('data cannot be null') | ||
setImmediate(function () { | ||
output = output.concat(data); cb() | ||
}) | ||
}, function (a, b) { | ||
if(!(b%2)) return a | ||
return (a||[]).concat(b) | ||
}, 10, function (err) { | ||
t.ok(err) | ||
}) | ||
pull( | ||
pull.count(30), | ||
writer | ||
) | ||
writer.abort(function (err) { | ||
t.notOk(err) | ||
t.end() | ||
}) | ||
}) | ||
tape('abort', function (t) { | ||
t.plan(2) | ||
var writer = createWrite(function write(data, cb) { | ||
if(data == null) throw new Error('data cannot be null') | ||
setImmediate(function () { | ||
output = output.concat(data); cb() | ||
}) | ||
}, function (a, b) { | ||
if(!(b%2)) return a | ||
return (a||[]).concat(b) | ||
}, 10, function (err) { | ||
t.ok(err) | ||
}) | ||
writer.abort(function (err) { | ||
t.notOk(err) | ||
t.end() | ||
}) | ||
pull( | ||
pull.count(30), | ||
writer | ||
) | ||
}) | ||
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
9452
233