Skip to content

Commit

Permalink
fix(operators): retry cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanGerbeth committed Nov 24, 2024
1 parent b8d4a74 commit c46cbbe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions packages/operators/src/request/request.js
Original file line number Diff line number Diff line change
@@ -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 => {
Expand All @@ -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)
);
};

Expand Down
2 changes: 1 addition & 1 deletion packages/operators/src/request/retry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
4 changes: 2 additions & 2 deletions packages/operators/src/request/retry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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')
);

Expand Down

0 comments on commit c46cbbe

Please sign in to comment.