Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: exhaustAll use exhaustMap to handle synchronous completion of in… #6911

Merged
merged 1 commit into from Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions spec/operators/exhaustAll-spec.ts
Expand Up @@ -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();
},
});
});
});
30 changes: 3 additions & 27 deletions 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
Expand Down Expand Up @@ -49,27 +47,5 @@ import { createOperatorSubscriber } from './OperatorSubscriber';
* completes before subscribing to the next.
*/
export function exhaustAll<O extends ObservableInput<any>>(): OperatorFunction<O, ObservedValueOf<O>> {
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);
}