From 3b588db90c9f17ccd4cbff227d8bbe9678adbba5 Mon Sep 17 00:00:00 2001 From: Nestor Qin Date: Wed, 31 Jul 2024 21:27:27 -0400 Subject: [PATCH] [Runtime] Add AbortSignal to fetchWithCache() --- web/src/artifact_cache.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/web/src/artifact_cache.ts b/web/src/artifact_cache.ts index 9690ed3320b9..794efdcedbc6 100644 --- a/web/src/artifact_cache.ts +++ b/web/src/artifact_cache.ts @@ -114,10 +114,11 @@ export class ArtifactCache implements ArtifactCacheTemplate { * fetch the corresponding url object in response or stored object format * @param url url * @param storetype the storage type for indexedDB + * @param signal an optional abort signal to abort fetching * @returns response in json, arraybuffer or pure response format */ - async fetchWithCache(url: string, storetype?: string): Promise { - await this.addToCache(url, storetype); + async fetchWithCache(url: string, storetype?: string, signal?: AbortSignal): Promise { + await this.addToCache(url, storetype, signal); const result = await this.cache.match(new Request(url)); if (result === undefined) { // Already called `addToCache()`, should expect the request in cache. @@ -242,8 +243,8 @@ export class ArtifactIndexedDBCache implements ArtifactCacheTemplate { }) } - async fetchWithCache(url: string, storetype?: string): Promise { - await this.addToCache(url, storetype); + async fetchWithCache(url: string, storetype?: string, signal?: AbortSignal): Promise { + await this.addToCache(url, storetype, signal); let result = await this.asyncGetHelper(url); if (result === null) { // previously null data in cache or somehow failed to add to cache, delete and retry