diff --git a/spec/operators/exhaustAll-spec.ts b/spec/operators/exhaustAll-spec.ts index c06e34b2bf..9c4f1fa668 100644 --- a/spec/operators/exhaustAll-spec.ts +++ b/spec/operators/exhaustAll-spec.ts @@ -287,4 +287,17 @@ describe('exhaust', () => { expect(sideEffects).to.deep.equal([0, 1, 2]); }); + + it('should handle synchronously completing inner observables', (done) => { + let i = 1; + of(of(1), of(2)) + .pipe(exhaustAll()) + .subscribe({ + next: (v) => expect(v).to.equal(i++), + complete: () => { + expect(i).to.equal(3); + done(); + }, + }); + }); }); diff --git a/src/internal/operators/exhaustAll.ts b/src/internal/operators/exhaustAll.ts index 62de6e8838..8004306be1 100644 --- a/src/internal/operators/exhaustAll.ts +++ b/src/internal/operators/exhaustAll.ts @@ -1,8 +1,6 @@ -import { Subscription } from '../Subscription'; import { OperatorFunction, ObservableInput, ObservedValueOf } from '../types'; -import { operate } from '../util/lift'; -import { innerFrom } from '../observable/innerFrom'; -import { createOperatorSubscriber } from './OperatorSubscriber'; +import { exhaustMap } from './exhaustMap'; +import { identity } from '../util/identity'; /** * Converts a higher-order Observable into a first-order Observable by dropping @@ -49,27 +47,5 @@ import { createOperatorSubscriber } from './OperatorSubscriber'; * completes before subscribing to the next. */ export function exhaustAll>(): OperatorFunction> { - return operate((source, subscriber) => { - let isComplete = false; - let innerSub: Subscription | null = null; - source.subscribe( - createOperatorSubscriber( - subscriber, - (inner) => { - if (!innerSub) { - innerSub = innerFrom(inner).subscribe( - createOperatorSubscriber(subscriber, undefined, () => { - innerSub = null; - isComplete && subscriber.complete(); - }) - ); - } - }, - () => { - isComplete = true; - !innerSub && subscriber.complete(); - } - ) - ); - }); + return exhaustMap(identity); }