summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobert Nagy <ronagy@icloud.com>2020-01-11 17:26:49 +0100
committerShelley Vohr <shelley.vohr@gmail.com>2020-02-17 11:21:32 -0800
commit5a95fa4aeb71b86fe0775cd7f6a704c63f2e7650 (patch)
treea27b27422fb05409f5d0b67065a787e69d064db9 /lib
parent20d0a0e9a78bed6b4f0fa4c8830024c0a93875b9 (diff)
downloadnode-new-5a95fa4aeb71b86fe0775cd7f6a704c63f2e7650.tar.gz
stream: normalize async iterator stream destroy
PR-URL: https://github.com/nodejs/node/pull/31316 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/internal/streams/async_iterator.js17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/internal/streams/async_iterator.js b/lib/internal/streams/async_iterator.js
index 93b676ff02..5eefba517b 100644
--- a/lib/internal/streams/async_iterator.js
+++ b/lib/internal/streams/async_iterator.js
@@ -22,6 +22,15 @@ const kStream = Symbol('stream');
let Readable;
+function destroy(stream, err) {
+ // request.destroy just do .end - .abort is what we want
+ if (typeof stream.abort === 'function') return stream.abort();
+ if (stream.req &&
+ typeof stream.req.abort === 'function') return stream.req.abort();
+ if (typeof stream.destroy === 'function') return stream.destroy(err);
+ if (typeof stream.close === 'function') return stream.close();
+}
+
function createIterResult(value, done) {
return { value, done };
}
@@ -141,7 +150,7 @@ const ReadableStreamAsyncIteratorPrototype = ObjectSetPrototypeOf({
resolve(createIterResult(undefined, true));
}
});
- stream.destroy();
+ destroy(stream);
});
},
}, AsyncIteratorPrototype);
@@ -156,11 +165,7 @@ const createReadableStreamAsyncIterator = (stream) => {
const src = stream;
stream = new Readable({ objectMode: true }).wrap(src);
- finished(stream, (err) => {
- if (typeof src.destroy === 'function') {
- src.destroy(err);
- }
- });
+ finished(stream, (err) => destroy(src, err));
}
const iterator = ObjectCreate(ReadableStreamAsyncIteratorPrototype, {