Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 933
thiagoh Avatar asked Oct 11 '17 02:10

thiagoh


1 Answers

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

Ammended CodePen

like image 173
Richard Matsen Avatar answered Oct 19 '22 08:10

Richard Matsen