Reputation: 465
Hi I want to call the function at the end of timer finished in rxjs.
this.timer$ = timer(1000, 1000).pipe(
scan(acc => acc = acc - 1000, milliseconds),
takeWhile(x => x >= 0),
tap(() => {
console.log('function finished')
})
)
The above code working but how can I define a function what should call after the timer expired.
I tried with tap
method but it is not working
Upvotes: 0
Views: 1043
Reputation: 11345
Use finalize
, takeWile
will complete the observable when condition match and trigger finalize
this.timer$ = timer(1000, 1000).pipe(
scan(acc => acc = acc - 1000, milliseconds),
takeWhile(x => x >= 0),
finalize(() => {
console.log('function finished')
})
)
Upvotes: 4
Reputation: 453
timer(1000,2000).pipe(take(4)).subscribe(console.log)
Did you say take
Upvotes: 0