0

I created Angular project here: https://stackblitz.com/edit/angular-5dmqwh

I have an issue with unnecessary executions that cause additional useless requests after isLoading gets false for every processed url. In console such undesired executions for url1 look like:

 `in map --> url1                       app.component.ts:26` 
 `before request --> url1               app.component.ts:29`

and for url2:

 `in map --> url2                       app.component.ts:26` 
 `before request --> url2               app.component.ts:29`

Please, review console to check projects output.

a_zatula
  • 438
  • 1
  • 3
  • 19

1 Answers1

0

It seems like you want the requests to stop, yet the stream has no way of knowing if this is an error. One way would be to check for error and switch the behavior, for example I checked if it's false and break the stream by throwing:

this.counter$.pipe(
  map(counter => {
    if (counter !== 0) {
      return true;
    } else {
      throw(new Error("explosion")); // This will stop the stream, but you should handle it
    }
  }),
).subscribe(val => {
   console.log('isLoading ...', val);
});
Claudiordgz
  • 3,023
  • 1
  • 21
  • 48