2

第二个concatMap没有被调用。

this.apiService.get()
               .pipe(
                   concatMap((data: MyModel) => {
                       if (data) {
                           // the following returns a MyModel Observable
                           return this.apiService.update(data);
                       } else {
                           return empty();
                       }
                   }),
                   concatMap((data: MyModel) => this.apiService.update(this.myOtherData))
               )
               .subscribe(data => log('completed'));

有任何想法吗?

4

1 回答 1

0

你必须双管。看看这里:https ://github.com/reactivex/rxjs/issues/4071

timer(10).pipe(
  concatMap(() => from(wait(20)).pipe(
    concatMap(() => {
      console.log('here');
      return from(wait(20)).pipe(
        tap(x => console.log('>', x))
      );
    })
  ))
)
.subscribe(x => console.log('>', x));

你知道 concatMap 如何需要一个 observable 来返回吗?好吧,我刚刚了解到,如果该源 observable concatMap 存在问题,则不会触发。当不是原因时,我很难对 concatMap 进行故障排除。

这也是我解决问题的方法,通过发送一个空的 observable 来确保我的设置是正确的。

this.sendRequest({'search': "be"}).pipe(
    concatMap(options => {
        console.log(options);
        return of([]);
    })
).subscribe(data => {
     console.log(data);
});
于 2019-05-16T00:39:58.183 回答