I have a function say main() which uses setInterval(async()=>{ console.log("Hello")},1000). The function inside setInterval() is executed 13 times i.e. Hello is printing 13 times. I want to check the value or the number of time this setInterval is running. Is there any way to do that?
main(){
setInterval(async()=>{
console.log("Hello")
await someApiCall();
console.log("World");
await anotherApiCall();
},1000)
}
This main function can be called multiple times. Can that be causing the number of print statement to increase.
You can keep a track of it using some counter.
If you want to keep track of setInterval across multiple calls of the main function.
let count = 0;
const main = () => {
setInterval(async() => {
console.log("Hello")
count++
console.log(count)
}, 1000)
}
main()
main()
If you want to keep track of setInterval within the main function.
const main = () => {
let count = 0;
setInterval(async() => {
console.log("Hello")
count++
console.log(count)
}, 1000)
}
main()