To use the timer
function from the rxjs
library in JavaScript, start by importing it:
index.tsx30 chars2 lines
Next, call the timer
function with the desired delay and period (if any), as follows:
index.tsx137 chars6 lines
The timer
function returns an Observable that emits a sequence of numbers every specified interval. To subscribe to this Observable and receive the emitted values, use the subscribe
method:
index.tsx242 chars10 lines
Keep in mind that in order to cancel the timer, you need to unsubscribe from the Observable:
index.tsx33 chars2 lines
gistlibby LogSnag