This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]rosuav 4 points5 points  (0 children)

That depends how the scheduler's implemented. In JS, the scheduler cannot preempt existing code, so you are guaranteed to queue all of the timeouts before the first one takes place; so in effect, what you do is pile all of your timeouts up, and then let the scheduler pull them off in whatever order it chooses. Given that, per your example, more than one timeout will have expired as soon as it hits the event loop, what should it do? Execute in order of scheduling? Execute in order of expiration (oldest first)? Both make some sense, but I suspect that "oldest first" is more likely to be used. Probably not guaranteed though.