@@ -1444,13 +1444,15 @@ export class Instance implements Disposable {
14441444 * @param device The device to be fetched to.
14451445 * @param cacheScope The scope identifier of the cache
14461446 * @param cacheType The type of the cache: "cache" or "indexedDB"
1447+ * @param signal An optional AbortSignal to abort the fetch
14471448 * @returns The meta data
14481449 */
14491450 async fetchNDArrayCache (
14501451 ndarrayCacheUrl : string ,
14511452 device : DLDevice ,
14521453 cacheScope = "tvmjs" ,
1453- cacheType = "cache"
1454+ cacheType = "cache" ,
1455+ signal ?: AbortSignal ,
14541456 ) : Promise < any > {
14551457 let artifactCache : ArtifactCacheTemplate ;
14561458 if ( cacheType === undefined || cacheType . toLowerCase ( ) === "cache" ) {
@@ -1465,7 +1467,8 @@ export class Instance implements Disposable {
14651467 const list = await artifactCache . fetchWithCache ( jsonUrl , "json" ) ;
14661468 await this . fetchNDArrayCacheInternal (
14671469 ndarrayCacheUrl ,
1468- list [ "records" ] as Array < NDArrayShardEntry > , device , artifactCache ) ;
1470+ list [ "records" ] as Array < NDArrayShardEntry > , device , artifactCache ,
1471+ signal ) ;
14691472 this . cacheMetadata = { ...this . cacheMetadata , ...( list [ "metadata" ] as Record < string , any > ) } ;
14701473 }
14711474
@@ -1477,12 +1480,14 @@ export class Instance implements Disposable {
14771480 * @param list The list of array data.
14781481 * @param device The device to store the data to.
14791482 * @param artifactCache The artifact cache
1483+ * @param signal An optional AbortSignal to abort the fetch
14801484 */
14811485 private async fetchNDArrayCacheInternal (
14821486 ndarrayCacheUrl : string ,
14831487 list : Array < NDArrayShardEntry > ,
14841488 device : DLDevice ,
1485- artifactCache : ArtifactCacheTemplate
1489+ artifactCache : ArtifactCacheTemplate ,
1490+ signal ?: AbortSignal ,
14861491 ) {
14871492 const perf = compact . getPerformance ( ) ;
14881493 const tstart = perf . now ( ) ;
@@ -1537,7 +1542,7 @@ export class Instance implements Disposable {
15371542 const shard = list [ i ] ;
15381543 const dataUrl = new URL ( shard . dataPath , ndarrayCacheUrl ) . href ;
15391544 try {
1540- await artifactCache . addToCache ( dataUrl , "arraybuffer" ) ;
1545+ await artifactCache . addToCache ( dataUrl , "arraybuffer" , signal ) ;
15411546 } catch ( err ) {
15421547 this . env . logger ( "Error: Cannot fetch " + dataUrl + " err= " + err ) ;
15431548 throw err ;
0 commit comments