-
Notifications
You must be signed in to change notification settings - Fork 3k
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 operators that fail the synchronous firehose test #5658
Comments
I've noticed some oddities with the behavior of Synchronous SubscriptionFrom within a synchronous subscription to the const subject = new BehaviorSubject<number>(0);
const obs$ = subject.pipe(
tap(() => console.log('before')),
exhaustMap((val) => {
return Promise.resolve(val * 100);
}),
tap(() => console.log('after')),
);
let i = 0;
obs$.subscribe(x => {
i++;
console.log(x)
if (i === 1) {
subject.next(i); // the `exhaustMap` causes this to have no effect
}
});
// output:
//
// before
// after
// 0
// before Asynchronous SubscriptionHowever, when there's an asynchronous subscription to the const subject = new BehaviorSubject<number>(0);
const obs$ = subject.pipe(
tap(() => console.log('before')),
exhaustMap((val) => {
return Promise.resolve(val * 100);
}),
switchMap((val) => {
return Promise.resolve(val);
}),
tap(() => console.log('after')),
);
let i = 0;
obs$.subscribe(x => {
i++;
console.log(x)
if (i === 1) {
subject.next(i);
}
});
// output:
//
// before
// after
// 0
// before
// after
// 100 CauseI believe that this is caused by the implementation of subscribeToPromise. When the promise is resolved, it first calls |
👋 @kobelb This is the behavior that I would expect. Because
Keep in mind that once an observable has completed, then it can no longer emit. So, it's not possible to complete before emitting the value. First it emits and then it completes. One way to get the behavior that you are expecting would be to observe the resulting observable of const subject = new BehaviorSubject<number>(0);
const obs$ = subject.pipe(
tap(() => console.log('before')),
exhaustMap((val) => {
return Promise.resolve(val * 100);
}),
observeOn(asapScheduler),
tap(() => console.log('after')),
);
let i = 0;
obs$.subscribe(x => {
i++;
console.log(x)
if (i === 1) {
subject.next(i); // the `exhaustMap` causes this to have no effect
}
});
I disagree. In the second snipped, the inner observable of const subject = new BehaviorSubject<number>(0);
const obs$ = subject.pipe(
tap(() => console.log('before')),
exhaustMap((val) => {
return Promise.resolve(val * 100);
}),
switchMap((val) => {
return of(val);
}),
tap(() => console.log('after')),
); |
- use known subscriber when possible instead of returned subscription - remove unused unsubscribe from refCount Operator - add teardown logic before calling subscribe when possible - enable remaining synchronous firehose tests fixes ReactiveX#5658
I had to make a change in ConnectableObservable by adding an internal method |
The following operators currently fail tests that were introduced in #5652 and those failing tests are currently skipped:
catchError
- see fix(catchError): inner synchronous observables will properly terminate #5655exhaust
- see test: enable now-passing firehose tests #5743exhaustMap
- see test: enable now-passing firehose tests #5743multicast
raceWith
- see test: enable now-passing firehose tests #5743refCount
repeat
- see Issue/5739 smaller operator creation #5742repeatWhen
- see Issue/5739 smaller operator creation #5742retry
- see Issue/5739 smaller operator creation #5742retryWhen
- see test: enable now-passing firehose tests #5743share
shareReplay
single
- see test: enable now-passing firehose tests #5743skipLast
- see test: enable remaining synchronous firehose tests #5749throttle
- see test: enable remaining synchronous firehose tests #5749timeout
- see test(timeout): enable skipped test #5748timeoutWith
- see test(timeout): enable skipped test #5748The tests are marked with
// TODO: fix firehose unsubscription
comments.Update: it's not going to be possible to make the
multicast
-based tests pass.The text was updated successfully, but these errors were encountered: