angular Rxjs tap guaranteed running code section

Viewed 374

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?') );
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
Related