Skip to content

Commit

Permalink
Solve TS error and tweak wording
Browse files Browse the repository at this point in the history
  • Loading branch information
sholladay authored Dec 10, 2024
1 parent 6de1156 commit 80be368
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions source/core/Ky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export class Ky {

// Delay the fetch so that body method shortcuts can set the Accept header
await Promise.resolve();
// Before using ky.request, _fetch clones a new Request for retries preparation.
// If retry is not needed, close the original Request ReadableStream for memory safety.
// Before using ky.request, _fetch clones it and saves the clone for future retries to use.
// If retry is not needed, close the cloned request's ReadableStream for memory safety.
let response = await ky._fetch();

for (const hook of ky._options.hooks.afterResponse) {
Expand Down Expand Up @@ -65,10 +65,9 @@ export class Ky {
throw error;
}

// Now, it can be determined that a retry is not needed,
// close the ReadableStream of the ky.request.
// Now that we know a retry is not needed, close the ReadableStream of the cloned request.
if (!ky.request.bodyUsed) {
await ky.request.arrayBuffer();
await ky.request.body?.cancel();
}

// If `onDownloadProgress` is passed, it uses the stream API internally
Expand Down

0 comments on commit 80be368

Please sign in to comment.