Being similar to native JS finally
, RxJS finalize
operator lets you run a function upon stream termination, regardless whether it completed, failed, or was unsubscribed from:
Open browser console to see the output
12345678910111213const { rxObserver } = require('api/v0.3'); const { timer } = require('rxjs'); const { finalize } = require('rxjs/operators'); timer(5) .pipe( finalize(()=> console.log(`Finished @ ${ Date.now() }ms`) ) ) .subscribe(rxObserver());
See finalize vs tap comparison