Fix timeout not works

This commit is contained in:
2024-01-02 15:11:26 +08:00
parent f6b5d25d9a
commit c0d86d3da5
3 changed files with 22 additions and 8 deletions

View File

@@ -46,10 +46,11 @@ export class ProgressReadable extends EventTarget {
this.#clearInterval();
return;
} else {
this.readed += v.value.byteLength;
const len = v.value.byteLength;
this.readed += len;
this.dispatchEvent("progress", this.readed);
c.enqueue(v.value);
if (v.value.byteLength != 0) {
if (len != 0) {
this.#last_readed = Date.now();
}
}
@@ -83,7 +84,7 @@ export class ProgressReadable extends EventTarget {
}
}
#setInterval() {
this.#timeout = setTimeout(() => {
this.#timeout = setInterval(() => {
const now = Date.now();
if (now - this.#last_readed > this.timeout) {
this.#is_timeout = true;