javascript - Execution order of multiple setTimeout() functions with same interval -


consider following javascript code:

function(){     settimeout(function() {         $("#output").append(" 1 ");     }, 1000);     settimeout(function() {         $("#output").append(" 2 ");     }, 1000); } 

you can see example on jsfiddle.

can sure value of #output "one two", in order? usually, handle problem this:

function(){     settimeout(function() {         $("#output").append(" 1 ");         $("#output").append(" 2 ");     }, 1000)); } 

but can not way because messages server tells me function execute (in example append "one" or append "two"), have execute small delay.

i tested code in internet explorer 9, firefox 14, chrome 20 , opera 12, , output "one two", can sure case?

the spec here.

my interpretation of settimeout step 8 in section 7.3 execution order is supposed guaranteed.

however, investigated issue because when window minimized , maximised in chrome, finding timeouts set in events coming external sources (like websockets or webworkers) being executed in wrong order. assume browser bug , fixed soon.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -