Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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 Expand Up @@ -44,7 +44,7 @@
tap(valid => (counter = counter * valid)),
// continue only if all observables are valid
filter(valid => valid),
tap(() => console.log(`retry: request - next: ${counter} in ${timeout(counter)}ms`)),

Check warning on line 47 in packages/operators/src/request/retry.js

View workflow job for this annotation

GitHub Actions / Install (ubuntu-latest, 20)

Unexpected console statement
delay(timeout(counter))
);
};
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
Loading