I calling to two functions: fn1
and fn2
. I use concatMap
to invoke other after the other.
I don't use exhustMap
and switchMap
because they lead to nested "callback-hell".
exhaustMap(() =>
fn1().pipe(
switchMap(() => fn2()))))
The one problem is how to get the results of fn1
and fn2
into next
function that happens after fn2 is invoked?
import { of } from 'rxjs';
import { concatMap, tap } from 'rxjs/operators';
console.clear();
const fn1 = () => {
console.log('in fn1');
return of('fn1');
};
const fn2 = () => {
console.log('in fn2');
return of('fn2');
};
of(1)
.pipe(
concatMap(() => fn1()),
concatMap(() => fn2()),
tap({
next: (a) => {
console.log({ a }); /// <---- here I want to get fn1, fn2 from the functions.
console.log('in tap!!!');
},
error: () => {
console.log('in tap error!!!');
},
complete: () => {
console.log('in tap complete');
},
})
)
.subscribe({
next: (r) => {
console.log({ r });
},
error: (e) => {
console.log({ e });
},
complete: () => {
console.log('complete');
},
});