[Runtime] Allow aborting fetchWithCache through AbortSignal (#17227)
[Runtime] Add AbortSignal to fetchWithCache()
diff --git a/web/src/artifact_cache.ts b/web/src/artifact_cache.ts
index 9690ed3..794efdc 100644
--- a/web/src/artifact_cache.ts
+++ b/web/src/artifact_cache.ts
@@ -114,10 +114,11 @@
* 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<any> {
- await this.addToCache(url, storetype);
+ async fetchWithCache(url: string, storetype?: string, signal?: AbortSignal): Promise<any> {
+ 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 @@
})
}
- async fetchWithCache(url: string, storetype?: string): Promise<any> {
- await this.addToCache(url, storetype);
+ async fetchWithCache(url: string, storetype?: string, signal?: AbortSignal): Promise<any> {
+ 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