From 0d363ce6fef7c05cb885c29db22e5d7f168ff814 Mon Sep 17 00:00:00 2001 From: Josep M Sobrepere Date: Tue, 4 May 2021 20:58:02 +0200 Subject: [PATCH] fix(retry): when # of retries is smaller than one --- spec/operators/retry-spec.ts | 13 +++++++++++++ src/internal/operators/retry.ts | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/spec/operators/retry-spec.ts b/spec/operators/retry-spec.ts index 8826c8155a0..613338b723f 100644 --- a/spec/operators/retry-spec.ts +++ b/spec/operators/retry-spec.ts @@ -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); + }) }); diff --git a/src/internal/operators/retry.ts b/src/internal/operators/retry.ts index 3a9dbe7ce43..9d41a4d2108 100644 --- a/src/internal/operators/retry.ts +++ b/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; @@ -69,7 +69,7 @@ export function retry(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;