stream-to-it
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "stream-to-it", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Convert Node.js streams to streaming iterables", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -89,2 +89,7 @@ # stream-to-it | ||
## Related | ||
* [`it-to-stream`](https://www.npmjs.com/package/it-to-stream) Convert streaming iterables to Node.js streams | ||
* [`it-pipe`](https://www.npmjs.com/package/it-pipe) Utility to "pipe" async iterables together | ||
## Contribute | ||
@@ -91,0 +96,0 @@ |
@@ -33,2 +33,11 @@ const getIterator = require('get-iterator') | ||
const getNext = async () => { | ||
try { | ||
return source.next() | ||
} catch (err) { | ||
writable.destroy(err) | ||
return errPromise.promise | ||
} | ||
} | ||
try { | ||
@@ -42,3 +51,3 @@ while (true) { | ||
finishPromise.promise, | ||
source.next() | ||
getNext() | ||
]) | ||
@@ -45,0 +54,0 @@ |
@@ -130,1 +130,25 @@ const test = require('ava') | ||
}) | ||
test('should destroy writable stream if source throws', async t => { | ||
const input = Array.from(Array(randomInt(5, 10)), () => randomBytes(1, 512)) | ||
const output = [] | ||
const source = { | ||
[Symbol.iterator]: function * () { | ||
yield * input[Symbol.iterator]() | ||
throw new Error('boom') | ||
} | ||
} | ||
const stream = new Writable({ | ||
write (chunk, enc, cb) { | ||
output.push(chunk) | ||
cb() | ||
} | ||
}) | ||
const err = await t.throwsAsync(pipe(source, toIterable.sink(stream))) | ||
t.is(err.message, 'boom') | ||
t.true(stream.destroyed) | ||
}) |
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
16381
385
101