-
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
DelayWhen subscribe to observable when it should not #5897
Comments
That's happening because
The behaviour that you are expecting would occur if import { concat, of, Subject, NEVER } from "rxjs";
import { delayWhen, withLatestFrom } from "rxjs/operators";
const source$ = of(1);
const willBeNeverEmitted$ = new Subject<number>().asObservable();
const shouldNotBeSubscribed$ = concat(source$, NEVER).pipe(
withLatestFrom(willBeNeverEmitted$)
);
const sourceForTest$ = of(1);
sourceForTest$
.pipe(delayWhen(() => shouldNotBeSubscribed$))
.subscribe(() => console.log("hello"));
shouldNotBeSubscribed$.subscribe(() => console.log("never called")); |
Thank you @josepot for your quick answer. |
That's not correct. The way that I hope that this helps. If I'm not mistaken, a poor's man implementation of let emptyValue: any = {}
const withLatestFrom = <L, T>(latest$: Observable<L>) => (
source$: Observable<T>,
) =>
new Observable<[T, L]>((subscriber) => {
let latestValue: L = emptyValue
return latest$
.subscribe((value) => {
latestValue = value
})
.add(
source$.subscribe(
(value) => {
if (latestValue !== emptyValue)
subscriber.next([value, latestValue])
},
(e) => subscriber.error(e),
() => subscriber.complete(),
),
)
}) |
FYI, @josepot @BrunoBeraudPW we have fixed the behavior of |
Hey,
I have a snippet that shows a strange behaviour of the delaywhen operator coupled with the one of the withLatestFrom
RxJS version: 6.6.3
Code to reproduce:
https://stackblitz.com/edit/delaywhen-bug?file=index.ts
Expected behavior:
console.log("hello") shouldn't be displayed
console.log("never called") shouldn't be displayed
Actual behavior:
console.log("hello") is display
console.log("never called") is do not displayed
Additional information:
If I change delayWhen operator by the mergeMap one, I have the expected behaviour.
The text was updated successfully, but these errors were encountered: