RxJS5 finalize operator not called

后端 未结 3 1644
無奈伤痛
無奈伤痛 2021-02-07 09:20

I\'m trying to trigger a callback when all my observables are executed. In my other, older project i used finally like so and that worked like a charm:



        
3条回答
  •  不思量自难忘°
    2021-02-07 09:56

    In observables, firing and completing are not the same thing.

    Even though each of the items emits a value, route.queryParams by definition will never complete since that is how Angular implements it, as a non terminating observable. You will need to manually complete it for your finalize to execute since combineLatest will only complete when EVERY observable being combined inside of it has completed.

    combineLatest(
      this.route.queryParams.pipe(take(1)), // take(1) will complete the observable after it has emitted one value
      this.myService.callDummy1(),
      this.myService.callDummy2()
    )
    .pipe(finalize(() => console.log('Does not work!')))
    .subscribe(results => ...);
    

    This will complete.

提交回复
热议问题