diff --git a/spec/operators/throttleTime-spec.ts b/spec/operators/throttleTime-spec.ts index fef0cd15b3..17e6472329 100644 --- a/spec/operators/throttleTime-spec.ts +++ b/spec/operators/throttleTime-spec.ts @@ -152,6 +152,15 @@ describe('throttleTime operator', () => { expectObservable(result).toBe(expected); expectSubscriptions(e1.subscriptions).toBe(e1subs); }); + asDiagram('throttleTime(fn, { leading: true, trailing: true })')('should handle a busy producer emitting a regular repeating sequence', () => { + const e1 = hot('abcdabcdabcdabcdabcd|'); + const subs = '^ !'; + const t = time('----| '); + const expected = 'a---a---a---a---a---(d|'; + + expectObservable(e1.pipe(throttleTime(t, rxTestScheduler, { leading: true, trailing: true }))).toBe(expected); + expectSubscriptions(e1.subscriptions).toBe(subs); + }); }); describe('throttleTime(fn, { leading: false, trailing: true })', () => { diff --git a/src/internal/operators/throttleTime.ts b/src/internal/operators/throttleTime.ts index 73a03007de..a43632a600 100644 --- a/src/internal/operators/throttleTime.ts +++ b/src/internal/operators/throttleTime.ts @@ -114,14 +114,15 @@ class ThrottleTimeSubscriber extends Subscriber { clearThrottle() { const throttled = this.throttled; if (throttled) { + throttled.unsubscribe(); + this.remove(throttled); + this.throttled = null; if (this.trailing && this._hasTrailingValue) { + this.add(this.throttled = this.scheduler.schedule>(dispatchNext, this.duration, { subscriber: this })); this.destination.next(this._trailingValue); this._trailingValue = null; this._hasTrailingValue = false; } - throttled.unsubscribe(); - this.remove(throttled); - this.throttled = null; } } }