Observable and ForkJoin , waiting the end of the first observable

Hi , I would be very gratefull if someone could help me with that or maybe rectifie me if i’m wrong.
What i’m doing here is that. I create array of observable, and i do a forkjoin on it

do(sendData: boolean) {
    let allObservable=[];
    allObservable.push(this.getContactFromDateObservable(this.DateSynchroContact));
    if (sendData) {
     allObservable.push(this.updateContactObservable());   
    } 
    return Observable.forkJoin(allObservable);
  }
post() {
    return new Promise((resolve, reject) => {
      this.http.getAsText(this.settings.url + "/service/check").subscribe((res) => {
        this.do(true).subscribe(result => {
          resolve(true);
        }, () => {
          reject(false);
        });
      }, () => {
        reject(false); 
      });
    });
  }
getContactFromDateObservable(dateSynchro){
    let actionRequest ="";
    return Observable.create(observer => {
      this.rest.ready().then(() => {
        return this.rest.get(this.FILECONFIG,actionRequest).subscribe((values : any) => {
          return this.Database.getContactsProvider().addOrUpdateContact(values).then(result =>{
            observer.next(true);
            observer.complete();
          });
        },() =>{
          observer.next(false);
          observer.complete();
        });
      });
    }); 
  }

And my problem is i need to wait the end of my first observe to keep going on the second one
Any suggestions ?
Please tell me if this is confuse will try to get more specific
Thanks in advance .

forkJoin won’t do this. Your English does not match your code. Please state exactly what you would like to achieve.

My problem is when i make this.do().subscribe Observable in my array allObservable, are made in async way and i would like to know if there any solution for waiting the end of my first Observable before the second one

You want to chain the observables? obs1 completes, then you start listening to obs2, obs2 completes, then you start listening to obs3?

Yes , exactly. It would be great !

let arrayOfObservables = // your array of Observables you want to chain;

function chainTwoObservables<T>(firstObs: Observable<T>, secondObs; Observable<T>): Observable<T> {
  return firstObs.concat(secondObs);
}

let chainOfObservables = arrayOfObservables.reduce(chainTwoObservables<whateverTypeYouNeed>);

You might have to tweak the syntax depending on which version of rxjs you are using. Maybe you will need concat inside a pipe. But that’s the general idea. Use the reduce function to chain all the way to the end, no matter how many Observables are in your array.

Thanks a lot i will try asap !

It is extremely rare that you want to be manually creating either Promises or Observables. The sheer volume of operators in Rx can be overwhelming at first, but please do whatever you can to use them.

There are a couple more red flags in your code: you are subscribing to and generating an Observable in the same place: I consider that a design flaw. Given the names of your functions, you are also attempting to mush side effects into an Observable stream. Generally, that’s something to be avoided if possible, but sometimes it really is needed. When you do really want to do that, the tap operator is your friend.

Since it looks like the reason you want to wait for one operation to complete before doing another is because the second operation needs the result of the first one, I would make that explicit in the chain, and definitely not rely on assignments to properties outside the chain, as I think you would have to be doing the way you have written things so far.

Generally, I would split your do() into two separate methods as opposed to having that boolean parameter, but for the sake of discussion let’s leave that the way it is.

frotzDateContact(push: boolean): Observable<Contact> {
  let rv = this.getContactFromDate(this.dateContactThingy);
  if (push) {
    rv = rv.pipe(tap(contact => this.updateContact(contact)));
  }
  return rv;
}