From c46cbbe1f06e9ab16ea551789fd3e8a3e85c7d1b Mon Sep 17 00:00:00 2001 From: StephanGerbeth Date: Sun, 24 Nov 2024 23:28:45 +0100 Subject: [PATCH] fix(operators): retry cleanup --- packages/operators/src/request/request.js | 10 +++++----- packages/operators/src/request/retry.js | 2 +- packages/operators/src/request/retry.test.js | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/operators/src/request/request.js b/packages/operators/src/request/request.js index 3fd8b6e..f693a7d 100644 --- a/packages/operators/src/request/request.js +++ b/packages/operators/src/request/request.js @@ -1,10 +1,10 @@ import { concatMap, from, throwError } from 'rxjs'; -import { cache as caching } from './cache'; +import { cache } from './cache'; import { resolveBlob, resolveJSON, resolveText } from './response'; -import { networkRetry } from './retry'; +import { retryWhenError } from './retry'; -export const request = ({ retry, cache } = {}) => { +export const request = ({ retry, cache: cacheOptions } = {}) => { return source => source.pipe( concatMap(req => { @@ -14,8 +14,8 @@ export const request = ({ retry, cache } = {}) => { return throwError(() => new Error('Failed to fetch: resource not valid')); } }), - networkRetry(retry), - caching(cache) + retryWhenError(retry), + cache(cacheOptions) ); }; diff --git a/packages/operators/src/request/retry.js b/packages/operators/src/request/retry.js index cabe408..a5479f8 100644 --- a/packages/operators/src/request/retry.js +++ b/packages/operators/src/request/retry.js @@ -16,7 +16,7 @@ import { connectionObservable } from '../../../observables/src/dom/window.js'; const defaultTimeout = count => Math.min(60000, Math.pow(count, 2) * 1000); -export const networkRetry = ({ timeout = defaultTimeout, count } = {}) => { +export const retryWhenError = ({ timeout = defaultTimeout, count } = {}) => { let counter = 0; return source => { diff --git a/packages/operators/src/request/retry.test.js b/packages/operators/src/request/retry.test.js index 16bddbd..1a5a23c 100644 --- a/packages/operators/src/request/retry.test.js +++ b/packages/operators/src/request/retry.test.js @@ -3,7 +3,7 @@ import { TestScheduler } from 'rxjs/testing'; import { beforeEach, describe, expect, test } from 'vitest'; import { log } from '../log'; -import { networkRetry } from './retry'; +import { retryWhenError } from './retry'; describe('request retry', () => { let testScheduler; @@ -26,7 +26,7 @@ describe('request retry', () => { // if you define a delay, you have to add the delay to the subscribe multiple times (num retries) const stream = cold('a|', { a: () => triggerVal.shift() }).pipe( map(fn => fn()), - networkRetry({ timeout: () => 5 }), + retryWhenError({ timeout: () => 5 }), log('marble:result') );