Chaining promises with RxJS

前端 未结 3 2059
青春惊慌失措
青春惊慌失措 2020-12-15 09:15

I\'m new to RxJS and FRP in general. I had the idea of converting an existing promise chain in my ExpressJS application to be an observable for practice. I am aware that thi

3条回答
  •  既然无缘
    2020-12-15 09:50

    flatMap turns an Observable of Observables into an Observable. It's used in many examples with Promises because often you have an observable and in the map function you want to create a promise for each "item" the observable emmits. Because every fromPromise call creates a new Observable, that makes it an "observable of observables". flatMap reduces that to a "flat" observable.

    In your example you do something different, you turn a single promise into an observable and want to chain it with another observable (also created form a single promise). Concat does what you are looking for, it chains two observables together.

    The error case will work as you would expect.

提交回复
热议问题