Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular Rxjs tap guaranteed running code section

Tags:

angular

rxjs

when using tap we have 3 sections: event, error, complete.

the complete section will be triggered only if no error occurred on the way. is there a way to guarantee that the complete section will run no matter what (like finally in exception handling)?

tap(ev => console.log('event: ', ev)
    err => console.log('error:', err),
    () => console.log('guaranteed section?') );
like image 856
gil Avatar asked Jul 11 '26 08:07

gil


1 Answers

You could alternatively use RxJS finalize operator, have a look at Documentation. finalize is executed when Observable completes or errors.

For example:

finalize(() => console.log('Sequence complete')) // Execute when the observable completes
like image 115
Goga Koreli Avatar answered Jul 13 '26 19:07

Goga Koreli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!