When I use pipe
and takeLast
, then the whole process stops.
Here is my original code:
this.request$.subscribe(req => {
this._service.run(req!).subscribe(res => {
this._service.fetch().subscribe(resources => {
console.log('hi'); // This 'hi' logs two times, but I want to get only the last 'hi'.
});
});
});
Here is my try:
this.request$.subscribe(req => {
this._service.run(req!).subscribe(res => {
this._service
.fetch()
.pipe(takeLast(1))
.subscribe({
next: x => console.log('got value ' + x),
error: err => console.error('something wrong occurred: ' + err),
complete: () => console.log('hi')
});
});
});
However, nothing happends in my try and nothing is logged anymore.
Updated my question
I have updated my second example as below, but not working yet:
this.request$.pipe(
mergeMap((req) => this._service.run(req!)),
mergeMap((res) => this._service.fetch().pipe(takeLast(1)))
).subscribe((resources) => {
console.log('hi'); // This line is not executed, but I expect to be executed one time.
});