0

I want to run come specific code after specific timing but with a efficient technique, Not with SetTimeout/SetInterval. Like request to Database to check data on a after specific time dialy. I want to query database at after 5:00 pm. So i write this code.

function checkVotingQuestionTime{
    var currentDate = new Date();
    if(currentDate .getHours =>5){
    //go to database
    }
}

But I have to write this code in setInterval(checkVotingQuestionTime, 60000); Is there any better way to do this job? I guess current code is performance killer. register event etc

Muhammad Faizan Khan
  • 10,013
  • 18
  • 97
  • 186
  • There are a number of these questions already (http://stackoverflow.com/questions/19088040/how-can-i-run-a-function-at-specific-time-date, http://stackoverflow.com/questions/4455282/call-a-javascript-function-at-a-specific-time-of-day, http://stackoverflow.com/questions/24741530/in-javascript-how-can-i-have-a-function-run-at-a-specific-time). I don't see any answers that suggest a better method than `setTimeout / setInterval` – Turnip Aug 24 '16 at 11:04
  • @Turnip Read my question against thanks. lots of difference – Muhammad Faizan Khan Aug 24 '16 at 11:05
  • I don't see any difference. – Turnip Aug 24 '16 at 11:08
  • i am talking out the method other then setTimeout or interval – Muhammad Faizan Khan Aug 24 '16 at 11:13
  • Yes. That's why I stated _"I don't see any answers that suggest a better method than setTimeout / setInterval"_ suggesting that you aren't going to find another solution. In order to know that a time has been reached, you have to poll the current time in some form of loop. There is no `timeChange` event. – Turnip Aug 24 '16 at 11:15
  • @MohammadFaizanKhan check this one [link](http://bunkat.github.io/later/) – Muhammad Usman Aug 24 '16 at 11:17

1 Answers1

0

I would recommend using a 3rd party solution like

http://bunkat.github.io/later/

or

http://bunkat.github.io/schedule/

The first will overwrite setInterval() for you, so that you can use later schedules instead of providing a timeoffset in milliseconds:

https://bunkat.github.io/later/execute.html#set-interval

wzr1337
  • 3,609
  • 5
  • 30
  • 53