rxjs concatMap似乎没有被调用

时间:2018-11-04 11:51:07

标签: angular rxjs observable concatmap

第二个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'));

有什么想法吗?

1 个答案:

答案 0 :(得分: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如何需要可观察的返回吗?好吧,我刚刚了解到,如果该源存在问题,则可触发的concatMap不会触发。当不是问题的原因时,我很想尝试对concatMap进行故障排除。

这也是我的问题,方法是发送一个空白的Observable以确保我的设置正确。

this.sendRequest({'search': "be"}).pipe(
    concatMap(options => {
        console.log(options);
        return of([]);
    })
).subscribe(data => {
     console.log(data);
});