Skip to content

Commit

Permalink
fix(retry): when # of retries is smaller than one
Browse files Browse the repository at this point in the history
  • Loading branch information
josepot committed May 4, 2021
1 parent bbc907f commit 4164e1f
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
Original file line number Diff line number Diff line change
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

expectObservable(result, unsub).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
})
});
4 changes: 2 additions & 2 deletions src/internal/operators/retry.ts
Original file line number Diff line number Diff line change
@@ -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 4164e1f

Please sign in to comment.