Skip to content

Commit

Permalink
fix: fix the linux patch (nodejs#2703)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak authored and crysmags committed Feb 21, 2024
1 parent 349c947 commit c235eb8
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions lib/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1174,16 +1174,12 @@ function fetchFinale (fetchParams, response) {

const byteStream = new ReadableStream({
readableStream: transformStream.readable,
async start () {
this._bodyReader = this.readableStream.getReader()
},
async pull (controller) {
// TODO(mcollina): removen this block, not sure why pull() is called twice
if (this.readableStream.locked) {
return
}

const reader = this.readableStream.getReader()

while (controller.desiredSize >= 0) {
const { done, value } = await reader.read()
const { done, value } = await this._bodyReader.read()

if (done) {
queueMicrotask(() => readableStreamClose(controller))
Expand Down Expand Up @@ -1985,8 +1981,8 @@ async function httpNetworkFetch (

// 11. Let pullAlgorithm be an action that resumes the ongoing fetch
// if it is suspended.
const pullAlgorithm = () => {
fetchParams.controller.resume()
const pullAlgorithm = async () => {
await fetchParams.controller.resume()
}

// 12. Let cancelAlgorithm be an algorithm that aborts fetchParams’s
Expand Down Expand Up @@ -2101,9 +2097,7 @@ async function httpNetworkFetch (
// into stream.
const buffer = new Uint8Array(bytes)
if (buffer.byteLength) {
try {
fetchParams.controller.controller.enqueue(buffer)
} catch {}
fetchParams.controller.controller.enqueue(buffer)
}

// 8. If stream is errored, then terminate the ongoing fetch.
Expand All @@ -2114,7 +2108,7 @@ async function httpNetworkFetch (

// 9. If stream doesn’t need more data ask the user agent to suspend
// the ongoing fetch.
if (!fetchParams.controller.controller.desiredSize) {
if (fetchParams.controller.controller.desiredSize <= 0) {
return
}
}
Expand Down

0 comments on commit c235eb8

Please sign in to comment.