From 2d09de9e62aeda08bd57577a640524fc31f3822b Mon Sep 17 00:00:00 2001 From: fw6 Date: Fri, 21 Jun 2024 11:19:02 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DVideoCache=E6=92=AD?= =?UTF-8?q?=E6=94=BE=E7=BC=93=E6=85=A2=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fw6 --- .../library/src/main/ets/ProxyCache.ts | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/OhosVideoCache/library/src/main/ets/ProxyCache.ts b/OhosVideoCache/library/src/main/ets/ProxyCache.ts index 854d41d2..6620ff3a 100644 --- a/OhosVideoCache/library/src/main/ets/ProxyCache.ts +++ b/OhosVideoCache/library/src/main/ets/ProxyCache.ts @@ -31,7 +31,7 @@ export default class ProxyCache { protected stopped: boolean = false; private readingInProgress: boolean = false; private percentsAvailable: number = -1; - private timeoutId: number = (0 - Number.MAX_VALUE); + private waitingResolver: (() => void) | null = null; constructor(source: Source, cache: Cache) { this.source = Preconditions.checkNotNull(source); @@ -76,8 +76,9 @@ export default class ProxyCache { console.debug("Shutdown proxy for " + this.source); try { this.stopped = true; - if (this.timeoutId != (0 - Number.MAX_VALUE)) { - clearTimeout((this.timeoutId)); + if (this.waitingResolver) { + this.waitingResolver(); + this.waitingResolver = null; } this.closeSource(); } catch (err) { @@ -100,20 +101,17 @@ export default class ProxyCache { } - private async waitForSourceData(): Promise { - let self = this; - return new Promise((resolve, reject) => { - self.timeoutId = setTimeout(() => { - if (self.timeoutId != (0 - Number.MAX_VALUE)) { - clearInterval(self.timeoutId) - self.timeoutId = (0 - Number.MAX_VALUE) - return resolve() - } - }, 1000) + private waitForSourceData() { + return new Promise((resolve) => { + this.waitingResolver = resolve; }) } private notifyNewCacheDataAvailable(cacheAvailable: number, sourceAvailable: number): void { + if (this.waitingResolver) { + this.waitingResolver(); + this.waitingResolver = null; + } this.onCacheAvailable(cacheAvailable, sourceAvailable); } -- Gitee