thiagoh
thiagoh

Reputation: 7408

RxJS observable concat not working

What is going on with the concat call? I know that if I replace concat by merge the code works correctly and the output is foo bar qux quux. I've read about Hot and Cold observables, and I know that for hot observables that might happen if the values are generated before the subscription, but my observables down there are cold, so I guess that's not the case.

const Rx = require('rxjs');

const observable1 = Rx.Observable.create((observer) => {
  observer.next('foo');
  observer.next('bar');
  return observer;
});
const observable2 = Rx.Observable.create((observer) => {
  observer.next('qux');
  observer.next('quux');
  return observer;
});
const result1 = observable1.concat(observable2);
result1.subscribe((x) => console.log(x));

// outputs
foo
bar

https://codepen.io/thiagoh/pen/WZyrRL

Upvotes: 11

Views: 4849

Answers (1)

Richard Matsen
Richard Matsen

Reputation: 23533

I believe observer1 needs to complete(), then concat can start outputting observer2.

Ammended CodePen

Upvotes: 11

Related Questions