From 6ded82e59d5f4149916ed011c03725e8386a6841 Mon Sep 17 00:00:00 2001 From: Graham Dennis Date: Thu, 15 Jun 2017 04:17:13 +1000 Subject: [PATCH] fix(audit): will now properly mirror source if durations are Observable.empty() (#2595) * fix(audit): mirror source if durations are Observable.empty() * refactor(audit): respond to feedback. --- spec/operators/audit-spec.ts | 12 ++++++++++++ src/operator/audit.ts | 7 ++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/spec/operators/audit-spec.ts b/spec/operators/audit-spec.ts index 6f0a455fb2..b151dfef9d 100644 --- a/spec/operators/audit-spec.ts +++ b/spec/operators/audit-spec.ts @@ -127,6 +127,18 @@ describe('Observable.prototype.audit', () => { expectSubscriptions(e1.subscriptions).toBe(e1subs); }); + it('should mirror source if durations are Observable.empty()', () => { + const e1 = hot('abcdefabcdefabcdefabcdefa|'); + const e1subs = '^ !'; + const e2 = Rx.Observable.empty(); + const expected = 'abcdefabcdefabcdefabcdefa|'; + + const result = e1.audit(() => e2); + + expectObservable(result).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(e1subs); + }); + it('should emit no values if duration is a never', () => { const e1 = hot('----abcdefabcdefabcdefabcdefa|'); const e1subs = '^ !'; diff --git a/src/operator/audit.ts b/src/operator/audit.ts index 41a14bd652..c30cd58e0a 100644 --- a/src/operator/audit.ts +++ b/src/operator/audit.ts @@ -85,7 +85,12 @@ class AuditSubscriber extends OuterSubscriber { if (duration === errorObject) { this.destination.error(errorObject.e); } else { - this.add(this.throttled = subscribeToResult(this, duration)); + const innerSubscription = subscribeToResult(this, duration); + if (innerSubscription.closed) { + this.clearThrottle(); + } else { + this.add(this.throttled = innerSubscription); + } } } }