multistream
Advanced tools
Comparing version 1.5.2 to 1.6.0
12
index.js
@@ -17,3 +17,3 @@ module.exports = MultiStream | ||
this._current = null | ||
this._queue = streams.map(toStreams2) | ||
this._queue = (typeof streams === 'function' ? streams : streams.map(toStreams2)) | ||
@@ -49,5 +49,7 @@ this._next() | ||
if (this._current && this._current.destroy) this._current.destroy() | ||
this._queue.forEach(function (stream) { | ||
if (stream.destroy) stream.destroy() | ||
}) | ||
if (typeof this._queue !== 'function') { | ||
this._queue.forEach(function (stream) { | ||
if (stream.destroy) stream.destroy() | ||
}) | ||
} | ||
@@ -60,3 +62,3 @@ if (err) this.emit('error', err) | ||
var self = this | ||
var stream = self._queue.shift() | ||
var stream = (typeof self._queue === 'function' ? self._queue() : self._queue.shift()) | ||
@@ -63,0 +65,0 @@ if (typeof stream === 'function') stream = toStreams2(stream()) |
{ | ||
"name": "multistream", | ||
"description": "A stream that emits multiple other streams one after another (streams2)", | ||
"version": "1.5.2", | ||
"version": "1.6.0", | ||
"author": "Feross Aboukhadijeh <feross@feross.org> (http://feross.org/)", | ||
@@ -6,0 +6,0 @@ "bugs": { |
@@ -59,2 +59,16 @@ # 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: | ||
```js | ||
var count = 0; | ||
var streams = function () { | ||
if (count > 3) return false | ||
count++ | ||
return fs.createReadStream(__dirname + '/numbers/' + count + '.txt') | ||
} | ||
MultiStream(streams).pipe(process.stdout) // => 123 | ||
``` | ||
### contributors | ||
@@ -64,2 +78,3 @@ | ||
- [Mathias Buus](https://github.com/mafintosh/) | ||
- [Yuri Astrakhan](https://github.com/nyurik/) | ||
@@ -66,0 +81,0 @@ ### license |
@@ -65,1 +65,21 @@ var concat = require('concat-stream') | ||
}) | ||
test('lazy stream via generator', function (t) { | ||
var count = 0 | ||
var streams = function () { | ||
if (count > 2) { | ||
return null | ||
} | ||
count++ | ||
return str(count.toString()) | ||
} | ||
new MultiStream(streams) | ||
.on('error', function (err) { | ||
t.fail(err) | ||
}) | ||
.pipe(concat(function (data) { | ||
t.equal(data.toString(), '123') | ||
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
32461
159
82