angular Rxjs tap guaranteed running code section

gil*_*gil 3 rxjs angular

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?') );
Run Code Online (Sandbox Code Playgroud)

Gog*_*eli 5

您也可以使用RxJS finalize运算符,查看Documentationfinalize当Observable完成或出错时执行。

例如:

finalize(() => console.log('Sequence complete')) // Execute when the observable completes
Run Code Online (Sandbox Code Playgroud)