Saturday, November 9, 2019

If you write your own polling in vanilla JavaScript you may want a delay between trips to the server as constant bombardment offers potential fatigue with little payoff.

var date = new Date();
date.setSeconds(date.getSeconds() + 1);
while (new Date() > date) {

 
 

You may find a full second to be a wait too long. If so, there is an alternative.

var date = new Date();
date.setMilliseconds(date.getMilliseconds() + 100);
while (new Date() > date) {

No comments:

Post a Comment