diff --git a/src/internal/operators/throttleTime.ts b/src/internal/operators/throttleTime.ts index baed7785c2..7f23be8fe8 100644 --- a/src/internal/operators/throttleTime.ts +++ b/src/internal/operators/throttleTime.ts @@ -130,7 +130,7 @@ class ThrottleTimeSubscriber extends Subscriber { this._hasTrailingValue = true; } } else { - this.add(this.throttled = this.scheduler.schedule>(dispatchNext, this.duration, { subscriber: this })); + this.throttle(); if (this.leading) { this.destination.next(value); } else if (this.trailing) { @@ -151,17 +151,27 @@ 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.destination.next(this._trailingValue); this._trailingValue = null; this._hasTrailingValue = false; + + if (this.leading && this.trailing) { + this.throttle(); + } } - throttled.unsubscribe(); - this.remove(throttled); - this.throttled = null; } } + + throttle() { + this.add(this.throttled = this.scheduler.schedule>(dispatchNext, this.duration, { subscriber: this })); + } } interface DispatchArg {