I need to send a countdown timer to the players in the room before the game starts.
So I need to maintain a timer for few seconds to send event on every second to the players in room
For this purpose what would be the best and efficient thing to do and why?
- Using Task scheduler
- Using setInterval
I would need a efficient way so that it won't be causing any issue when many rooms are active and many countdown events have to be sent if many rooms are active at a time
Efficient solution for countdown timer
Re: Efficient solution for countdown timer
Hi,
using the scheduler seems a good fit.
You can simply add a non-repeating Task that runs after 1 second and keeps track of the countdown. The task will run and send a message to the client, then check if the countdown is complete. If not it will reschedule itself.
For this you can use the global TaskScheduler, the one you access via:
and maybe reconfigure its thread pool, to 10-12 threads. This should be enough to handle hundreds of tasks, probably even thousands, since the Task is very light.
To change the default number of threads: AdminTool > Server Configurator
Hope it helps
using the scheduler seems a good fit.
You can simply add a non-repeating Task that runs after 1 second and keeps track of the countdown. The task will run and send a message to the client, then check if the countdown is complete. If not it will reschedule itself.
For this you can use the global TaskScheduler, the one you access via:
Code: Select all
getApi().getSystemScheduler();
and maybe reconfigure its thread pool, to 10-12 threads. This should be enough to handle hundreds of tasks, probably even thousands, since the Task is very light.
To change the default number of threads: AdminTool > Server Configurator
Hope it helps
Who is online
Users browsing this forum: Baidu [Spider], Stevenor and 102 guests