I implemented an RxJS architecture based on the answer to this question: Pipe RxJS observable to existing subject
Later, I noticed that the observable randomly closed and I've spent a lot of time to find the cause. In the end, appeared that this snippet was causing the closing:
const delayed = Observable.of(arr.shift()).delay(1000);
merge(otherObs, delayed).subscribe(mySubject);
The of
/delay
observable was completing after 1 second, and it piped the completion to mySubject
, making it unable to receive other values, including the ones sent by otherObs
in case they arrived after the timeout.
Here is a StackBlitz that shows the problem.
How can I avoid mySubject
completes, without explicitly writing the callbacks?