What happens to setTimeout when the computer goes to sleep?

As far as I’ve tested, it just stops and resumes after the computer wakes up. When the computer awakes the setInterval/setTimeout is unaware that any time passed. I don’t think you should rely on the accuracy of setTimeout/Interval for time critical stuff. For google chrome I discovered recently that any timeout/interval (that is shorter than … Read more

How to stop a setTimeout loop?

setTimeout returns a timer handle, which you can use to stop the timeout with clearTimeout. So for instance: function setBgPosition() { var c = 0, timer = 0; var numbers = [0, -120, -240, -360, -480, -600, -720]; function run() { Ext.get(‘common-spinner’).setStyle(‘background-position’, numbers[c++] + ‘px 0px’); if (c >= numbers.length) { c = 0; } … Read more

Express.js Response Timeout

There is already a Connect Middleware for Timeout support: var timeout = express.timeout // express v3 and below var timeout = require(‘connect-timeout’); //express v4 app.use(timeout(120000)); app.use(haltOnTimedout); function haltOnTimedout(req, res, next){ if (!req.timedout) next(); } If you plan on using the Timeout middleware as a top-level middleware like above, the haltOnTimedOut middleware needs to be the … Read more

Delay jquery hover event?

Use the hoverIntent plugin for jquery: http://cherne.net/brian/resources/jquery.hoverIntent.html It’s absolutely perfect for what you describe and I’ve used it on nearly every project that required mouseover activation of menus etc… There is one gotcha to this approach, some interfaces are devoid of a ‘hover’ state eg. mobile browsers like safari on the iphone. You may be … Read more

How to make `setInterval` behave more in sync, or how to use `setTimeout` instead?

You can create a setTimeout loop using recursion: function timeout() { setTimeout(function () { // Do Something Here // Then recall the parent function to // create a recursive loop. timeout(); }, 1000); } The problem with setInterval() and setTimeout() is that there is no guarantee your code will run in the specified time. By … Read more

find the time left in a setTimeout()?

Just for the record, there is a way to get the time left in node.js: var timeout = setTimeout(function() {}, 3600 * 1000); setInterval(function() { console.log(‘Time left: ‘+getTimeLeft(timeout)+’s’); }, 2000); function getTimeLeft(timeout) { return Math.ceil((timeout._idleStart + timeout._idleTimeout – Date.now()) / 1000); } Prints: $ node test.js Time left: 3599s Time left: 3597s Time left: 3595s … Read more

Get return value from setTimeout [duplicate]

You need to use Promises for this. They are available in ES6 but can be polyfilled quite easily: function x() { return new Promise((resolve, reject) => { setTimeout(() => { resolve(‘done!’); }); }); } x().then((done) => { console.log(done); // –> ‘done!’ }); With async/await in ES2017 it becomes nicer if inside an async function: async … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)