Is setTimeout with no delay the same as executing the function instantly?

It won’t necessarily run right away, neither will explicitly setting the delay to 0. The reason is that setTimeout removes the function from the execution queue and it will only be invoked after JavaScript has finished with the current execution queue. console.log(1); setTimeout(function() {console.log(2)}); console.log(3); console.log(4); console.log(5); //console logs 1,3,4,5,2 for more details see http://javascriptweblog.wordpress.com/2010/06/28/understanding-javascript-timers/

How to test a function which has a setTimeout with jasmine?

The overall approach varies based on your Jasmine version. Jasmine 1.3 You can use waitsFor: it( “Disable all submit buttons”, function() { // Get a button var $button = $( ‘#ai1ec_subscribe_users’ ); // Call the function utility_functions.block_all_submit_and_ajax( $button.get(0) ); // Wait 100ms for all elements to be disabled. waitsFor(‘button to be disabled’, function(){ var found … Read more

How to tell .hover() to wait?

This will make the second function wait 2 seconds (2000 milliseconds) before executing: $(‘.icon’).hover(function() { clearTimeout($(this).data(‘timeout’)); $(‘li.icon > ul’).slideDown(‘fast’); }, function() { var t = setTimeout(function() { $(‘li.icon > ul’).slideUp(‘fast’); }, 2000); $(this).data(‘timeout’, t); }); It also clears the timeout when the user hovers back in to avoid crazy behavior. This is not a very … Read more

What is the equivalent to a JavaScript setInterval/setTimeout in Android/Java?

As always with Android there’s lots of ways to do this, but assuming you simply want to run a piece of code a little bit later on the same thread, I use this: new android.os.Handler(Looper.getMainLooper()).postDelayed( new Runnable() { public void run() { Log.i(“tag”, “This’ll run 300 milliseconds later”); } }, 300); .. this is pretty … Read more