I just read this SO question RxJS Promise Composition (passing data) and had a question.
The setting is the same as the aforementioned question: I have 3 promises.
const p1 = () => Promise.resolve(1);
const p2 = x => { const val = x + 1; return Promise.resolve(val); };
const p3 = x => {
const isEven = x => x % 2 === 0;
return Promise.resolve(isEven(x));
};
And I'm chaining them, as per the answer, like this:
var chainedPromises$ =
Rx.Observable.just()
.flatMap(p1)
.flatMap(p2)
.flatMap(p3);
However, chainedPromises$
only fires up once, at the end of all the promise chain, with the resolved value true
. Namely:
chainedPromises$.subscribe(function(x){console.log(x)}); // Logs `true`
How can I change chainedPromises$
so that it fires once at the end of each promise? Ie:
chainedPromises$.subscribe(function(x){console.log(x)});
// Logs `1`
// Logs `2`
// Logs `true`