@@ -248,9 +248,13 @@ export class Saturn {
248
248
* @param {string } [opts.url]
249
249
* @param {number } [opts.connectTimeout=5000]
250
250
* @param {number } [opts.downloadTimeout=0]
251
+ * @param {AbortController } [opts.controller]
251
252
* @returns {Promise<AsyncIterable<Uint8Array>> }
252
253
*/
253
254
async * fetchContentWithFallback ( cidPath , opts = { } ) {
255
+ const upstreamController = opts . controller ;
256
+ delete opts . controller ;
257
+
254
258
let lastError = null
255
259
// we use this to checkpoint at which chunk a request failed.
256
260
// this is temporary until range requests are supported.
@@ -261,6 +265,13 @@ export class Saturn {
261
265
}
262
266
263
267
const fetchContent = async function * ( ) {
268
+ const controller = new AbortController ( ) ;
269
+ opts . controller = controller ;
270
+ if ( upstreamController ) {
271
+ upstreamController . signal . addEventListener ( 'abort' , ( ) => {
272
+ controller . abort ( ) ;
273
+ } ) ;
274
+ }
264
275
let byteCount = 0
265
276
const byteChunks = await this . fetchContent ( cidPath , opts )
266
277
for await ( const chunk of byteChunks ) {
@@ -298,7 +309,7 @@ export class Saturn {
298
309
let fallbackCount = 0
299
310
const nodes = this . nodes
300
311
for ( let i = 0 ; i < nodes . length ; i ++ ) {
301
- if ( fallbackCount > this . opts . fallbackLimit ) {
312
+ if ( fallbackCount > this . opts . fallbackLimit || upstreamController ?. signal . aborted ) {
302
313
return
303
314
}
304
315
if ( opts . raceNodes ) {
0 commit comments