diff --git a/src/functions/ConcurrencyLimitedFetch.mjs b/src/functions/ConcurrencyLimitedFetch.mjs index 87e75a8..397c8a3 100644 --- a/src/functions/ConcurrencyLimitedFetch.mjs +++ b/src/functions/ConcurrencyLimitedFetch.mjs @@ -47,6 +47,7 @@ export default class ConcurrencyLimitedFetch { if (task.args.options.signal.aborted) { task.reject(task.args.options.signal.reason); + this._process(); return; } diff --git a/src/functions/ConcurrencyLimitedFetch.test.mjs b/src/functions/ConcurrencyLimitedFetch.test.mjs index 42e29a8..a2849fd 100644 --- a/src/functions/ConcurrencyLimitedFetch.test.mjs +++ b/src/functions/ConcurrencyLimitedFetch.test.mjs @@ -71,6 +71,29 @@ describe('ConcurrencyLimitedFetch', () => { await assert.rejects(aborted, 'AbortError: This operation was aborted'); assert.strictEqual(fetch.mock.callCount(), 10); }); + + it('fetches the next queued when encountering an aborted in the queue', async (t) => { + const fetcher = new ConcurrencyLimitedFetch(); + + t.mock.method(global, 'fetch', () => new Promise(() => {})); + for (let i = 0; i < 9; i++) { + fetcher.fetch('', makeFetchOptions()); + } + + // Will resolve on next flush + t.mock.method(global, 'fetch', () => Promise.resolve()); + fetcher.fetch('', makeFetchOptions()); + + const abortController = new AbortController(); + assert.rejects(fetcher.fetch('', makeFetchOptions({ abortController }))); + abortController.abort(); + + // Will be fetched when 10th resolves + fetcher.fetch('', makeFetchOptions()); + + await flushPromises(); + assert.strictEqual(fetch.mock.callCount(), 2); + }); }); function makeFetchOptions({ abortController } = {}) {