Skip to content

Commit

Permalink
fix(retry): when # of retries is smaller than one (#6359)
Browse files Browse the repository at this point in the history
  • Loading branch information
josepot committed May 5, 2021
1 parent c5dbfd6 commit e797bd7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
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

0 comments on commit e797bd7

Please sign in to comment.