Skip to content

Commit ed7c896

Browse files
committed
fixup
1 parent ca4f12c commit ed7c896

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

lib/internal/streams/operators.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,21 @@ module.exports.map = function map(stream, fn, options) {
4848
callback(err);
4949
}
5050
});
51+
const state = ret._readableState;
5152

5253
async function read () {
53-
if (ret.readableLength && ret.readableLength >= ret.readableHighWaterMark) {
54-
return;
55-
}
56-
5754
try {
5855
reading = true;
59-
while (queue.length && !ret.destroyed) {
56+
while (
57+
queue.length &&
58+
!state.destroyed &&
59+
(!state.length || state.length < state.highWaterMark)
60+
) {
6061
const [err, val] = await queue.shift();
6162
if (err) {
6263
ret.destroy(err);
63-
} else if (!ret.push(val)) {
64-
break;
6564
} else {
65+
ret.push(val);
6666
pump();
6767
}
6868
}
@@ -82,7 +82,7 @@ module.exports.map = function map(stream, fn, options) {
8282

8383
function enqueue(val) {
8484
queue.push(val);
85-
if (!reading) {
85+
if (!reading && state.length < state.highWaterMark) {
8686
read();
8787
}
8888
}
@@ -93,7 +93,6 @@ module.exports.map = function map(stream, fn, options) {
9393
if (val === null) {
9494
return;
9595
}
96-
9796
enqueue(wrap(val));
9897
}
9998
}

0 commit comments

Comments
 (0)