multistream
Advanced tools
Comparing version 1.6.1 to 2.0.0
15
index.js
@@ -60,5 +60,16 @@ module.exports = MultiStream | ||
var self = this | ||
var stream = (typeof self._queue === 'function' ? toStreams2(self._queue()) : self._queue.shift()) | ||
if (typeof self._queue === 'function') { | ||
self._queue(function (err, stream) { | ||
if (err) return self.destroy(err) | ||
self._gotNextStream(toStreams2(stream)) | ||
}) | ||
} else { | ||
var stream = self._queue.shift() | ||
if (typeof stream === 'function') stream = toStreams2(stream()) | ||
self._gotNextStream(stream) | ||
} | ||
} | ||
if (typeof stream === 'function') stream = toStreams2(stream()) | ||
MultiStream.prototype._gotNextStream = function (stream) { | ||
var self = this | ||
@@ -65,0 +76,0 @@ if (!stream) { |
{ | ||
"name": "multistream", | ||
"description": "A stream that emits multiple other streams one after another (streams2)", | ||
"version": "1.6.1", | ||
"version": "2.0.0", | ||
"author": "Feross Aboukhadijeh <feross@feross.org> (http://feross.org/)", | ||
@@ -6,0 +6,0 @@ "bugs": { |
@@ -59,16 +59,17 @@ # multistream [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] | ||
Alternativelly, streams may be created by a generator function: | ||
Alternativelly, streams may be created by an asyncronous "factory" function: | ||
```js | ||
var count = 0; | ||
var streams = function () { | ||
if (count > 3) return false | ||
function factory (cb) { | ||
if (count > 3) return cb(null, null) | ||
count++ | ||
return fs.createReadStream(__dirname + '/numbers/' + count + '.txt') | ||
setTimeout(function () { | ||
cb(null, fs.createReadStream(__dirname + '/numbers/' + count + '.txt')) | ||
}, 100) | ||
} | ||
MultiStream(streams).pipe(process.stdout) // => 123 | ||
MultiStream(factory).pipe(process.stdout) // => 123 | ||
``` | ||
### contributors | ||
@@ -75,0 +76,0 @@ |
@@ -66,13 +66,11 @@ var concat = require('concat-stream') | ||
test('lazy stream via generator', function (t) { | ||
test('lazy stream via factory', function (t) { | ||
var count = 0 | ||
var streams = function () { | ||
if (count > 2) { | ||
return null | ||
} | ||
function factory (cb) { | ||
if (count > 2) return cb(null, null) | ||
count++ | ||
return str(count.toString()) | ||
cb(null, str(count.toString())) | ||
} | ||
new MultiStream(streams) | ||
new MultiStream(factory) | ||
.on('error', function (err) { | ||
@@ -87,9 +85,26 @@ t.fail(err) | ||
test('lazy stream via generator (classic)', function (t) { | ||
test('lazy stream via factory (factory returns error)', function (t) { | ||
t.plan(2) | ||
var count = 0 | ||
var streams = function () { | ||
if (count > 2) { | ||
return null | ||
} | ||
function factory (cb) { | ||
if (count > 2) return cb(new Error('factory error')) | ||
count++ | ||
cb(null, str(count.toString())) | ||
} | ||
new MultiStream(factory) | ||
.on('error', function (err) { | ||
t.pass('got error', err) | ||
}) | ||
.on('close', function () { | ||
t.pass('got close') | ||
}) | ||
.resume() | ||
}) | ||
test('lazy stream via factory (classic)', function (t) { | ||
var count = 0 | ||
function factory (cb) { | ||
if (count > 2) return cb(null, null) | ||
count++ | ||
var s = through() | ||
@@ -100,6 +115,6 @@ process.nextTick(function () { | ||
}) | ||
return s | ||
cb(null, s) | ||
} | ||
new MultiStream(streams) | ||
new MultiStream(factory) | ||
.on('error', function (err) { | ||
@@ -106,0 +121,0 @@ t.fail(err) |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
33650
206
83
0