skip to content

finalize

 

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

1
2
3
4
5
6
7
8
9
10
11
12
13
const { 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());

0msstartcomplete00

See finalize vs tap comparison