0

I am trying to run observables in sequence (when firstObservableStream is done, then deal with secondObservableStream). This whey i am trying to emulate some async stuff. For example delete-old-image --> upload new image ---> subscribe to output and so on.

I have a short example code:

import { Observable, of } from 'rxjs';
import { merge, concat } from 'rxjs/operators';

const emmit$ = Observable.create(function(observer) {
  setTimeout( ()=> observer.next('emmit #1'), 40);
  setTimeout( ()=> observer.next('emmit #2'), 5000);
});

const process$ = Observable.create(function(observer) {
  setTimeout( ()=> observer.next('process #1'), 2500);
  setTimeout( ()=> observer.next('process #2'), 400);
});

const combined$ =  emmit$.pipe(concat(process$));
combined$.subscribe( (val) =>{
  console.log(val);
});

What i expect as output: emmit#1 --> emmit#2 --> process#1 --> process#2

And the real output is: emmit#1 --> emmit#2

Like if $process do not participate in sequence at all

Mariik
  • 135
  • 2
  • 11
  • 1
    Possible duplicate of [How to force observables to execute in sequence?](https://stackoverflow.com/questions/43336549/how-to-force-observables-to-execute-in-sequence) – frido Feb 18 '19 at 16:05
  • Your `process$` Observable gets never subscribed to because the previous Observable in the sequence (`emmit$`) never completes. For `concat` to work all Observables have to complete. Use `observer.complete()` to complete your Observables when they are done emitting. – frido Feb 18 '19 at 22:15

0 Answers0