What is the maximum number of setTimeout() methods that can be run at the same time usin Node.JS

Viewed 1337

I have a java script file which runs using nodeJS. I am using the setTimeout() method to create a sort of timer which will run some code after a user specified time. As multiple users will be using this code will there be a problem with running lets say 1000 setTimeout methods in parallel? Is there a maximum number that can run simultaneously or will it just make the program run slower the more I have?

2 Answers

There is no hard limit to how many setTimeouts you can have at once, it'll just use more memory the more you have, but if you have a lot and exact timing isn't important you may just want to load the events into an array and have a single setInterval going through the array and running them if the timeout finished.

--If there is a block of code that should execute multiple times, setInterval() can be used to execute that code. setInterval() takes a function argument that will run an infinite number of times with a given millisecond delay as the second argument.

I believe that for every user they have their own set timeout function and when they get over then their request will be fulfilled. One whose set timeout ends first will get the high priority.

Related