Why doesn't this result in an infinite loop? #6071
Answered
by
cartant
Sawtaytoes
asked this question in
Q&A
|
Can someone explain why this isn't an infinite loop? Seems to be something about execution order with This code has a subject calling const subject$ = new Subject();
subject$
.pipe(
startWith(null),
switchMap(() => (
throwError('error')
.pipe(
catchError(() => {
subject$
.next()
return of(null);
}),
)
)),
)
.subscribe()There are three fixes to make this infinitely loop:
startWith(null),
delay(0),
merge(
of(null),
subject$,
)
catchError(() => {
if (isFirstTime) {
isFirstTime = false
setTimeout(() => {
subject$
.next()
})
}
else {
subject$
.next()
}
return of(null);
}),Looks like this might be related to an issue I had a few years back when trying to do the same thing; calling a subject's |
Answered by
cartant
Mar 2, 2021
Replies: 2 comments 9 replies
|
My guess is that |
8 replies
Answer selected by
Sawtaytoes
|
are we just talking about behavior or is there a use case to this? |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

My guess is that
startWithemits before it subscribes to its source, so it's not subscribed at the time thenextcall is made. Feature. Not a bug.