Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
rexagod committed Apr 27, 2020
1 parent a77341e commit 9fdb1a6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion doc/api/stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -1677,7 +1677,8 @@ added:
-->

* `iterable` {Iterable} Object implementing the `Symbol.asyncIterator` or
`Symbol.iterator` iterable protocol. Throws if a null value is passed.
`Symbol.iterator` iterable protocol. Emits an 'error' event if a null
value is passed.
* `options` {Object} Options provided to `new stream.Readable([options])`.
By default, `Readable.from()` will set `options.objectMode` to `true`, unless
this is explicitly opted out by setting `options.objectMode` to `false`.
Expand Down
6 changes: 4 additions & 2 deletions lib/internal/streams/from.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ function from(Readable, iterable, opts) {
await close();
} else {
const res = await value;
if (res === null) readable.destroy(new ERR_STREAM_NULL_VALUES());
if (readable.push(res)) {
if (res === null) {
reading = false;
readable.destroy(new ERR_STREAM_NULL_VALUES());
} else if (readable.push(res)) {
next();
} else {
reading = false;
Expand Down
5 changes: 2 additions & 3 deletions test/parallel/test-readable-from-iterator-closing.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,17 @@ async function closeAfterNullYielded() {
const finallyMustCall = mustCall();
const dataMustCall = mustCall(3);

function* infiniteGenerate() {
function* generate() {
try {
yield 'a';
yield 'a';
yield 'a';
while (true) yield null;
} finally {
finallyMustCall();
}
}

const stream = Readable.from(infiniteGenerate());
const stream = Readable.from(generate());

stream.on('data', (chunk) => {
dataMustCall();
Expand Down

0 comments on commit 9fdb1a6

Please sign in to comment.