Skip to content

Commit e47d3e2

Browse files
committed
better
1 parent afde522 commit e47d3e2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/utils/stream.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export async function fetchStream(url, requestOptions = {}, options = {}) {
4848
let contentLength = null
4949

5050
return new ReadableStream({
51-
async pull(controller) {
51+
async pull(stream) {
5252
for (let attempt = 0; attempt <= maxRetries; attempt++) {
5353
try {
5454
const response = await fetchRange(startByte, abortController.signal)
@@ -60,19 +60,19 @@ export async function fetchStream(url, requestOptions = {}, options = {}) {
6060
while (true) {
6161
const { done, value } = await reader.read()
6262
if (done) {
63-
controller.close()
63+
stream.close()
6464
return
6565
}
6666

6767
startByte += value.byteLength
68-
controller.enqueue(value)
68+
stream.enqueue(value)
6969
options.onProgress?.(startByte / contentLength)
7070
}
7171
} catch (err) {
7272
console.warn(`Attempt ${attempt + 1} failed:`, err)
7373
if (attempt === maxRetries) {
7474
abortController.abort()
75-
controller.error(new Error('Max retries reached', { cause: err }))
75+
stream.error(new Error('Max retries reached', { cause: err }))
7676
return
7777
}
7878
await new Promise((res) => setTimeout(res, retryDelay))

0 commit comments

Comments
 (0)