GeezerVison is showing github.com — stream: add readableDidRead · nodejs/node@8306051
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/_http_incoming.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -87,6 +87,7 @@ function IncomingMessage(socket) { | 87 | 87 | this.statusMessage = null; | 88 | 88 | this.client = socket; | 89 | 89 |
| | 90 | + // TODO: Deprecate and remove. | 90 | 91 | this._consuming = false; | 91 | 92 | // Flag for when we decide that this message cannot possibly be | 92 | 93 | // read by the user, so there's no point continuing to handle it. | |
Collapse file Copy file name to clipboardExpand all lines: lib/_http_server.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -802,7 +802,7 @@ function resOnFinish(req, res, socket, state, server) { | 802 | 802 | // If the user never called req.read(), and didn't pipe() or | 803 | 803 | // .resume() or .on('data'), then we call req._dump() so that the | 804 | 804 | // bytes will be pulled off the wire. | 805 | | - if (!req._consuming && !req._readableState.resumeScheduled) | | 805 | + if (!req.readableDidRead) | 806 | 806 | req._dump(); | 807 | 807 |
| 808 | 808 | // Make sure the requestTimeout is cleared before finishing. | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/streams/readable.js +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -171,6 +171,8 @@ function ReadableState(options, stream, isDuplex) { | 171 | 171 | // If true, a maybeReadMore has been scheduled. | 172 | 172 | this.readingMore = false; | 173 | 173 |
| | 174 | + this.didRead = false; | | 175 | + | 174 | 176 | this.decoder = null; | 175 | 177 | this.encoding = null; | 176 | 178 | if (options && options.encoding) { | @@ -542,6 +544,8 @@ Readable.prototype.read = function(n) { | 542 | 544 | if (ret !== null) | 543 | 545 | this.emit('data', ret); | 544 | 546 |
| | 547 | + state.didRead = true; | | 548 | + | 545 | 549 | return ret; | 546 | 550 | }; | 547 | 551 |
| @@ -845,7 +849,9 @@ function pipeOnDrain(src, dest) { | 845 | 849 |
| 846 | 850 | if ((!state.awaitDrainWriters || state.awaitDrainWriters.size === 0) && | 847 | 851 | EE.listenerCount(src, 'data')) { | | 852 | + // TODO(ronag): Call resume() instead? | 848 | 853 | state.flowing = true; | | 854 | + state.didRead = true; | 849 | 855 | flow(src); | 850 | 856 | } | 851 | 857 | }; | @@ -993,6 +999,7 @@ Readable.prototype.resume = function() { | 993 | 999 | function resume(stream, state) { | 994 | 1000 | if (!state.resumeScheduled) { | 995 | 1001 | state.resumeScheduled = true; | | 1002 | + state.didRead = true; | 996 | 1003 | process.nextTick(resume_, stream, state); | 997 | 1004 | } | 998 | 1005 | } | @@ -1177,6 +1184,13 @@ ObjectDefineProperties(Readable.prototype, { | 1177 | 1184 | } | 1178 | 1185 | }, | 1179 | 1186 |
| | 1187 | + readableDidRead: { | | 1188 | + enumerable: false, | | 1189 | + get: function() { | | 1190 | + return this._readableState.didRead; | | 1191 | + } | | 1192 | + }, | | 1193 | + | 1180 | 1194 | readableHighWaterMark: { | 1181 | 1195 | enumerable: false, | 1182 | 1196 | get: function() { | |
Collapse file Copy file name to clipboard +24Lines changed: 24 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | +require('../common'); | | 3 | +const assert = require('assert'); | | 4 | +const Readable = require('stream').Readable; | | 5 | + | | 6 | +{ | | 7 | + const readable = new Readable({ | | 8 | + read: () => {} | | 9 | + }); | | 10 | + | | 11 | + assert.strictEqual(readable.readableDidRead, false); | | 12 | + readable.read(); | | 13 | + assert.strictEqual(readable.readableDidRead, true); | | 14 | +} | | 15 | + | | 16 | +{ | | 17 | + const readable = new Readable({ | | 18 | + read: () => {} | | 19 | + }); | | 20 | + | | 21 | + assert.strictEqual(readable.readableDidRead, false); | | 22 | + readable.resume(); | | 23 | + assert.strictEqual(readable.readableDidRead, true); | | 24 | +} |
|