【问题标题】:show the error and resume the stream显示错误并恢复流
【发布时间】:2017-08-26 21:32:11
【问题描述】:

我有一个实时搜索,但如果由于某种原因 forkJoin 失败,一切都会停止工作。我在错误后尝试寻找的任何新词都不起作用。如何显示错误并正常恢复流,以便我可以搜索其他单词?

this.search$
  .distinctUntilChanged()
  .switchMap((query) => Rx.Observable.forkJoin(sources)) // If this fails the search stops working
  .subscribe((results) => console.log(results));

【问题讨论】:

    标签: angular react-native stream rxjs reactjs-flux


    【解决方案1】:

    试试这个:

    this.search$
      .distinctUntilChanged()
      .switchMap((query) => Rx.Observable.forkJoin(sources)
        // return empty results object, I used an empty array...
        .catch(error => Observable.of([])))
      .subscribe((results) => console.log(results));
    

    请注意,catch() 位于 forkJoin(),而不是 switchMap()...

    【讨论】:

    • 我也需要显示错误,把这个也放在catch里面?
    猜你喜欢
    • 2016-01-16
    • 1970-01-01
    • 2017-08-03
    • 2016-03-12
    • 1970-01-01
    • 2019-03-28
    • 1970-01-01
    • 2021-12-15
    • 1970-01-01
    相关资源
    最近更新 更多