Skip to content

Commit 1314e35

Browse files
committed
fixup
1 parent 6e5f6fc commit 1314e35

File tree

4 files changed

+5
-104
lines changed

4 files changed

+5
-104
lines changed

lib/_http_incoming.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ function IncomingMessage(socket) {
8787
this.statusMessage = null;
8888
this.client = socket;
8989

90-
// TODO: Deprecate and remove.
9190
this._consuming = false;
9291
// Flag for when we decide that this message cannot possibly be
9392
// read by the user, so there's no point continuing to handle it.

lib/_http_server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ function resOnFinish(req, res, socket, state, server) {
804804
// If the user never called req.read(), and didn't pipe() or
805805
// .resume() or .on('data'), then we call req._dump() so that the
806806
// bytes will be pulled off the wire.
807-
if (!req.readableDidRead)
807+
if (!req._consuming && !req._readableState.resumeScheduled)
808808
req._dump();
809809

810810
// Make sure the requestTimeout is cleared before finishing.

lib/internal/streams/compose.js

Lines changed: 4 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,17 @@
22

33
const pipeline = require('internal/streams/pipeline');
44
const Duplex = require('internal/streams/duplex');
5-
const { createDeferredPromise } = require('internal/util');
65
const { destroyer } = require('internal/streams/destroy');
7-
const from = require('internal/streams/from');
86
const {
9-
isIterable,
10-
isReadableNodeStream,
11-
isWritableNodeStream,
127
isNodeStream,
13-
isDestroyed,
14-
isReadableFinished,
15-
isWritableEnded,
168
} = require('internal/streams/utils');
17-
const {
18-
PromiseResolve,
19-
} = primordials;
209
const {
2110
AbortError,
2211
codes: {
23-
ERR_INVALID_ARG_TYPE,
2412
ERR_INVALID_ARG_VALUE,
25-
ERR_INVALID_RETURN_VALUE,
2613
ERR_MISSING_ARGS,
2714
},
2815
} = require('internal/errors');
29-
const assert = require('internal/assert');
3016

3117
function isReadable(stream) {
3218
const r = isReadableNodeStream(stream);
@@ -70,18 +56,18 @@ module.exports = function compose(...streams) {
7056
}
7157

7258
if (streams.length === 1) {
73-
return makeDuplex(streams[0], 'streams[0]');
59+
return Duplex.from(streams[0]);
7460
}
7561

7662
const orgStreams = [...streams];
7763

7864
if (typeof streams[0] === 'function') {
79-
streams[0] = makeDuplex(streams[0], 'streams[0]');
65+
streams[0] = Duplex.from(streams[0]);
8066
}
8167

8268
if (typeof streams[streams.length - 1] === 'function') {
8369
const idx = streams.length - 1;
84-
streams[idx] = makeDuplex(streams[idx], `streams[${idx}]`);
70+
streams[idx] = Duplex.from(streams[idx]);
8571
}
8672

8773
for (let n = 0; n < streams.length; ++n) {
@@ -134,7 +120,7 @@ module.exports = function compose(...streams) {
134120
// Implement Writable/Readable/Duplex traits.
135121
// See, https://github.com/nodejs/node/pull/33515.
136122
d = new ComposeDuplex({
137-
highWaterMark: 1,
123+
// TODO (ronag): highWaterMark?
138124
writableObjectMode: !!head?.writableObjectMode,
139125
readableObjectMode: !!tail?.writableObjectMode,
140126
writable,
@@ -220,82 +206,3 @@ module.exports = function compose(...streams) {
220206

221207
return d;
222208
};
223-
224-
function makeDuplex(stream, name) {
225-
let ret;
226-
if (typeof stream === 'function') {
227-
assert(stream.length > 0);
228-
229-
const { value, write, final } = fromAsyncGen(stream);
230-
231-
if (isIterable(value)) {
232-
ret = from(ComposeDuplex, value, {
233-
objectMode: true,
234-
highWaterMark: 1,
235-
write,
236-
final
237-
});
238-
} else if (typeof value?.then === 'function') {
239-
const promise = PromiseResolve(value)
240-
.then((val) => {
241-
if (val != null) {
242-
throw new ERR_INVALID_RETURN_VALUE('nully', name, val);
243-
}
244-
})
245-
.catch((err) => {
246-
destroyer(ret, err);
247-
});
248-
249-
ret = new ComposeDuplex({
250-
objectMode: true,
251-
highWaterMark: 1,
252-
readable: false,
253-
write,
254-
final(cb) {
255-
final(() => promise.then(cb, cb));
256-
}
257-
});
258-
} else {
259-
throw new ERR_INVALID_RETURN_VALUE(
260-
'Iterable, AsyncIterable or AsyncFunction', name, value);
261-
}
262-
} else if (isNodeStream(stream)) {
263-
ret = stream;
264-
} else if (isIterable(stream)) {
265-
ret = from(ComposeDuplex, stream, {
266-
objectMode: true,
267-
highWaterMark: 1,
268-
writable: false
269-
});
270-
} else {
271-
throw new ERR_INVALID_ARG_TYPE(
272-
name,
273-
['Stream', 'Iterable', 'AsyncIterable', 'Function'],
274-
stream)
275-
;
276-
}
277-
return ret;
278-
}
279-
280-
function fromAsyncGen(fn) {
281-
let { promise, resolve } = createDeferredPromise();
282-
const value = fn(async function*() {
283-
while (true) {
284-
const { chunk, done, cb } = await promise;
285-
process.nextTick(cb);
286-
if (done) return;
287-
yield chunk;
288-
({ promise, resolve } = createDeferredPromise());
289-
}
290-
}());
291-
292-
return {
293-
value,
294-
write(chunk, encoding, cb) {
295-
resolve({ chunk, done: false, cb });
296-
},
297-
final(cb) {
298-
resolve({ done: true, cb });
299-
}
300-
};
301-
}

lib/internal/streams/readable.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,6 @@ Readable.prototype.read = function(n) {
527527
this.emit('data', ret);
528528
}
529529

530-
state.didRead = true;
531-
532530
return ret;
533531
};
534532

@@ -832,9 +830,7 @@ function pipeOnDrain(src, dest) {
832830

833831
if ((!state.awaitDrainWriters || state.awaitDrainWriters.size === 0) &&
834832
EE.listenerCount(src, 'data')) {
835-
// TODO(ronag): Call resume() instead?
836833
state.flowing = true;
837-
state.didRead = true;
838834
flow(src);
839835
}
840836
};
@@ -982,7 +978,6 @@ Readable.prototype.resume = function() {
982978
function resume(stream, state) {
983979
if (!state.resumeScheduled) {
984980
state.resumeScheduled = true;
985-
state.didRead = true;
986981
process.nextTick(resume_, stream, state);
987982
}
988983
}

0 commit comments

Comments
 (0)