8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7ce1cc9 commit 4b04bf8Copy full SHA for 4b04bf8
lib/internal/streams/async_iterator.js
@@ -11,6 +11,7 @@ const {
11
} = primordials;
12
13
const finished = require('internal/streams/end-of-stream');
14
+const destroyImpl = require('internal/streams/destroy');
15
16
const kLastResolve = Symbol('lastResolve');
17
const kLastReject = Symbol('lastReject');
@@ -22,15 +23,6 @@ const kStream = Symbol('stream');
22
23
24
let Readable;
25
-function destroy(stream, err) {
26
- // request.destroy just do .end - .abort is what we want
27
- if (typeof stream.abort === 'function') return stream.abort();
28
- if (stream.req &&
29
- typeof stream.req.abort === 'function') return stream.req.abort();
30
- if (typeof stream.destroy === 'function') return stream.destroy(err);
31
- if (typeof stream.close === 'function') return stream.close();
32
-}
33
-
34
function createIterResult(value, done) {
35
return { value, done };
36
}
@@ -92,7 +84,7 @@ function finish(self, err) {
92
84
resolve(createIterResult(undefined, true));
93
85
94
86
});
95
- destroy(stream, err);
87
+ destroyImpl.destroyer(stream, err);
96
88
97
89
98
90
@@ -172,7 +164,7 @@ const createReadableStreamAsyncIterator = (stream) => {
172
164
173
165
const src = stream;
174
166
stream = new Readable({ objectMode: true }).wrap(src);
175
- finished(stream, (err) => destroy(src, err));
167
+ finished(stream, (err) => destroyImpl.destroyer(src, err));
176
168
177
169
178
170
const iterator = ObjectCreate(ReadableStreamAsyncIteratorPrototype, {
lib/internal/streams/destroy.js
@@ -128,8 +128,21 @@ function errorOrDestroy(stream, err) {
128
stream.emit('error', err);
129
130
131
+function isRequest(stream) {
132
+ return stream && stream.setHeader && typeof stream.abort === 'function';
133
+}
134
+
135
+// Normalize destroy for legacy.
136
+function destroyer(stream, err) {
137
+ // request.destroy just do .end - .abort is what we want
138
+ if (isRequest(stream)) return stream.abort();
139
+ if (isRequest(stream.req)) return stream.req.abort();
140
+ if (typeof stream.destroy === 'function') return stream.destroy(err);
141
+ if (typeof stream.close === 'function') return stream.close();
142
143
144
module.exports = {
145
+ destroyer,
146
destroy,
147
undestroy,
148
errorOrDestroy
lib/internal/streams/pipeline.js
@@ -12,6 +12,7 @@ const {
let eos;
const { once } = require('internal/util');
const {
ERR_INVALID_ARG_TYPE,
18
ERR_INVALID_RETURN_VALUE,
@@ -28,14 +29,6 @@ function isRequest(stream) {
return stream && stream.setHeader && typeof stream.abort === 'function';
-function destroyStream(stream, err) {
- if (isRequest(stream)) return stream.abort();
- if (isRequest(stream.req)) return stream.req.abort();
37
38
39
function destroyer(stream, reading, writing, final, callback) {
40
callback = once(callback);
41
let destroyed = false;
@@ -46,15 +39,15 @@ function destroyer(stream, reading, writing, final, callback) {
46
destroyed = true;
47
const readable = stream.readable || isRequest(stream);
48
if (err || !final || !readable) {
49
- destroyStream(stream, err);
42
50
43
51
44
callback(err);
52
45
53
54
return (err) => {
55
if (destroyed) return;
56
57
58
callback(err || new ERR_STREAM_DESTROYED('pipe'));
59
};
60