Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(retry): when # of retries is smaller than one #6359

Merged
merged 1 commit into from May 5, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions spec/operators/retry-spec.ts
Expand Up @@ -326,4 +326,17 @@ describe('retry operator', () => {

expect(sideEffects).to.deep.equal([0, 1, 2]);
});

it('should not alter the source when the number of retries is smaller than 1', () => {
const source = cold('--1-2-3-#');
const subs = ['^ !'];

const expected = '--1-2-3-#';
const unsub = ' !';

const result = source.pipe(retry(0));

expectObservable(result, unsub).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
})
});
4 changes: 2 additions & 2 deletions src/internal/operators/retry.ts
@@ -1,8 +1,8 @@
import { MonoTypeOperatorFunction } from '../types';
import { operate } from '../util/lift';
import { Subscription } from '../Subscription';
import { EMPTY } from '../observable/empty';
import { OperatorSubscriber } from './OperatorSubscriber';
import { identity } from '../util/identity';

export interface RetryConfig {
count: number;
Expand Down Expand Up @@ -69,7 +69,7 @@ export function retry<T>(configOrCount: number | RetryConfig = Infinity): MonoTy
const { count, resetOnSuccess = false } = config;

return count <= 0
? () => EMPTY
? identity
: operate((source, subscriber) => {
let soFar = 0;
let innerSub: Subscription | null;
Expand Down