Observable forkJoin not firing

后端 未结 5 715
暗喜
暗喜 2020-12-18 19:21

I\'m trying to user forkJoin on two Observables. One of them starts as a stream... If I subscribe to them directly I get a response, forkJoin isn\'

5条回答
  •  [愿得一人]
    2020-12-18 20:04

    forkJoin emits only when all inner observables have completed. If you need an equivalent of forkJoin that just listens to a single emission from each source, use combineLatest + take(1)

    combineLatest(
      this.statuses$,
      this.companies$,
    )
    .pipe(
      take(1),
    )
    .subscribe(([statuses, companies]) => {
      console.log('forkjoin');
      this._countStatus(statuses, companies);
    });
    

    As soon as both sources emit, combineLatest will emit and take(1) will unsubscribe immediately after that.

提交回复
热议问题