pull-stream
Advanced tools
Comparing version 3.0.1 to 3.1.0
{ | ||
"name": "pull-stream", | ||
"description": "minimal pull stream", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"homepage": "https://github.com/dominictarr/pull-stream", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -88,10 +88,12 @@ # pull-stream | ||
//read source and log it. | ||
var logger = function (read) { | ||
read(null, function next(end, data) { | ||
if(end === true) return | ||
if(end) throw end | ||
var logger = function () { | ||
return function (read) { | ||
read(null, function next(end, data) { | ||
if(end === true) return | ||
if(end) throw end | ||
console.log(data) | ||
read(null, next) | ||
}) | ||
console.log(data) | ||
read(null, next) | ||
}) | ||
} | ||
} | ||
@@ -103,3 +105,3 @@ ``` | ||
```js | ||
var rand = random()) | ||
var rand = random() | ||
var log = logger() | ||
@@ -106,0 +108,0 @@ |
60
sinks.js
@@ -17,5 +17,7 @@ 'use strict' | ||
var drain = exports.drain = function (op, done) { | ||
var read, abort | ||
return function (read) { | ||
function sink (_read) { | ||
read = _read | ||
if(abort) return sink.abort() | ||
//this function is much simpler to write if you | ||
@@ -25,29 +27,35 @@ //just use recursion, but by using a while loop | ||
;(function next() { | ||
var loop = true, cbed = false | ||
while(loop) { | ||
cbed = false | ||
read(null, function (end, data) { | ||
cbed = true | ||
if(end) { | ||
var loop = true, cbed = false | ||
while(loop) { | ||
cbed = false | ||
read(null, function (end, data) { | ||
cbed = true | ||
if(end = end || abort) { | ||
loop = false | ||
if(done) done(end === true ? null : end) | ||
else if(end && end !== true) | ||
throw end | ||
} | ||
else if(op && false === op(data) || abort) { | ||
loop = false | ||
read(abort || true, done || function () {}) | ||
} | ||
else if(!loop){ | ||
next() | ||
} | ||
}) | ||
if(!cbed) { | ||
loop = false | ||
if(done) done(end === true ? null : end) | ||
else if(end && end !== true) | ||
throw end | ||
return | ||
} | ||
else if(op && false === op(data)) { | ||
loop = false | ||
read(true, done || function () {}) | ||
} | ||
else if(!loop){ | ||
next() | ||
} | ||
}) | ||
if(!cbed) { | ||
loop = false | ||
return | ||
} | ||
} | ||
})() | ||
})() | ||
} | ||
sink.abort = function (err) { | ||
abort = err || true | ||
if(read) return read(abort, function () {}) | ||
} | ||
return sink | ||
} | ||
@@ -110,1 +118,5 @@ | ||
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
51782
32
1146
293