Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,27 @@ const ndjson = async function * (source) {

const streamToAsyncIterator = function (source) {
if (isAsyncIterator(source)) {
// Workaround for https://github.com/node-fetch/node-fetch/issues/766
if (source.writable && source.readable) {
const iter = source[Symbol.asyncIterator]()

const wrapper = {
next: iter.next.bind(iter),
return: () => {
if (source.writableEnded) {
source.destroy()
}

return iter.return()
},
[Symbol.asyncIterator]: () => {
return wrapper
}
}

return wrapper
}

return source
}

Expand Down