Skip to content

Commit 0a20d50

Browse files
committed
stream: remove thenable support
Remove support for returning thenables in stream implementation methods. This is causing more confusion and issues than it's worth. Refs: #39535
1 parent d8f1823 commit 0a20d50

File tree

5 files changed

+6
-380
lines changed

5 files changed

+6
-380
lines changed

lib/internal/streams/destroy.js

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,7 @@ function _destroy(self, err, cb) {
106106
}
107107
}
108108
try {
109-
const result = self._destroy(err || null, onDestroy);
110-
if (result != null) {
111-
const then = result.then;
112-
if (typeof then === 'function') {
113-
then.call(
114-
result,
115-
function() {
116-
process.nextTick(onDestroy, null);
117-
},
118-
function(err) {
119-
process.nextTick(onDestroy, err);
120-
});
121-
}
122-
}
109+
self._destroy(err || null, onDestroy);
123110
} catch (err) {
124111
onDestroy(err);
125112
}
@@ -285,20 +272,7 @@ function constructNT(stream) {
285272
}
286273

287274
try {
288-
const result = stream._construct(onConstruct);
289-
if (result != null) {
290-
const then = result.then;
291-
if (typeof then === 'function') {
292-
then.call(
293-
result,
294-
function() {
295-
process.nextTick(onConstruct, null);
296-
},
297-
function(err) {
298-
process.nextTick(onConstruct, err);
299-
});
300-
}
301-
}
275+
stream._construct(onConstruct);
302276
} catch (err) {
303277
onConstruct(err);
304278
}

lib/internal/streams/readable.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -493,18 +493,7 @@ Readable.prototype.read = function(n) {
493493

494494
// Call internal read method
495495
try {
496-
const result = this._read(state.highWaterMark);
497-
if (result != null) {
498-
const then = result.then;
499-
if (typeof then === 'function') {
500-
then.call(
501-
result,
502-
nop,
503-
function(err) {
504-
errorOrDestroy(this, err);
505-
});
506-
}
507-
}
496+
this._read(state.highWaterMark);
508497
} catch (err) {
509498
errorOrDestroy(this, err);
510499
}

lib/internal/streams/transform.js

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,8 @@ function Transform(options) {
107107
}
108108

109109
function final(cb) {
110-
let called = false;
111110
if (typeof this._flush === 'function' && !this.destroyed) {
112-
const result = this._flush((er, data) => {
113-
called = true;
111+
this._flush((er, data) => {
114112
if (er) {
115113
if (cb) {
116114
cb(er);
@@ -128,33 +126,6 @@ function final(cb) {
128126
cb();
129127
}
130128
});
131-
if (result !== undefined && result !== null) {
132-
try {
133-
const then = result.then;
134-
if (typeof then === 'function') {
135-
then.call(
136-
result,
137-
(data) => {
138-
if (called)
139-
return;
140-
if (data != null)
141-
this.push(data);
142-
this.push(null);
143-
if (cb)
144-
process.nextTick(cb);
145-
},
146-
(err) => {
147-
if (cb) {
148-
process.nextTick(cb, err);
149-
} else {
150-
process.nextTick(() => this.destroy(err));
151-
}
152-
});
153-
}
154-
} catch (err) {
155-
process.nextTick(() => this.destroy(err));
156-
}
157-
}
158129
} else {
159130
this.push(null);
160131
if (cb) {
@@ -180,9 +151,7 @@ Transform.prototype._write = function(chunk, encoding, callback) {
180151
const wState = this._writableState;
181152
const length = rState.length;
182153

183-
let called = false;
184-
const result = this._transform(chunk, encoding, (err, val) => {
185-
called = true;
154+
this._transform(chunk, encoding, (err, val) => {
186155
if (err) {
187156
callback(err);
188157
return;
@@ -203,38 +172,6 @@ Transform.prototype._write = function(chunk, encoding, callback) {
203172
this[kCallback] = callback;
204173
}
205174
});
206-
if (result !== undefined && result != null) {
207-
try {
208-
const then = result.then;
209-
if (typeof then === 'function') {
210-
then.call(
211-
result,
212-
(val) => {
213-
if (called)
214-
return;
215-
216-
if (val != null) {
217-
this.push(val);
218-
}
219-
220-
if (
221-
wState.ended ||
222-
length === rState.length ||
223-
rState.length < rState.highWaterMark ||
224-
rState.length === 0) {
225-
process.nextTick(callback);
226-
} else {
227-
this[kCallback] = callback;
228-
}
229-
},
230-
(err) => {
231-
process.nextTick(callback, err);
232-
});
233-
}
234-
} catch (err) {
235-
process.nextTick(callback, err);
236-
}
237-
}
238175
};
239176

240177
Transform.prototype._read = function() {

lib/internal/streams/writable.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -692,20 +692,7 @@ function callFinal(stream, state) {
692692
state.pendingcb++;
693693

694694
try {
695-
const result = stream._final(onFinish);
696-
if (result != null) {
697-
const then = result.then;
698-
if (typeof then === 'function') {
699-
then.call(
700-
result,
701-
function() {
702-
process.nextTick(onFinish, null);
703-
},
704-
function(err) {
705-
process.nextTick(onFinish, err);
706-
});
707-
}
708-
}
695+
stream._final(onFinish);
709696
} catch (err) {
710697
onFinish(stream, state, err);
711698
}

0 commit comments

Comments
 (0)