Is there a faster way to yield to Javascript event loop than setTimeout(0)?

Yes, the message queue will have higher importance than timeouts one, and will thus fire at higher frequency. You can bind to that queue quite easily with the MessageChannel API: let i = 0; let j = 0; const channel = new MessageChannel(); channel.port1.onmessage = messageLoop; function messageLoop() { i++; // loop channel.port2.postMessage(“”); } function … Read more

How do I clear this setInterval inside a function?

The setInterval method returns a handle that you can use to clear the interval. If you want the function to return it, you just return the result of the method call: function intervalTrigger() { return window.setInterval( function() { if (timedCount >= markers.length) { timedCount = 0; } google.maps.event.trigger(markers[timedCount], “click”); timedCount++; }, 5000 ); }; var … 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

Maximum call stack size exceeded on SetTimeout recursive function (Javascript) [duplicate]

The problem is here: setTimeout($scope.clickFilter(), 1000); Putting () after the function reference means that you want the function to be called, immediately, at that point in the code. What you probably want instead is something like: setTimeout($scope.clickFilter.bind($scope), 1000); which will pass a function reference to setTimeout(), as is required, and ensure that the function will … Read more