ling
ling

Reputation: 10037

is javascript setTimeout guaranteed to fire

I've read this article: http://ejohn.org/blog/how-javascript-timers-work/ and I understand that setInterval might drop some callback execution if the page is too busy.

I don't see how this would apply to setTimeout too, so is it safe to assume that setTimeout will always be executed (possibly some delay), or is it a case where a the setTimeout is dropped because of a busy process?

Upvotes: 3

Views: 1573

Answers (2)

Peter Aron Zentai
Peter Aron Zentai

Reputation: 11750

Yes. A function passed to setTimeout will execute at some point. While its timing is not guaranteed.

Upvotes: 3

user5004821
user5004821

Reputation:

Yes - the "too busy" issue w/ set interval is touched upon somewhat in the last section about setInterval on the MDN. Set timeout, however, will always execute after some delay (it may not be the exact delay, ie your set timeout could be 5ms, but if the call stack is still full after the 5ms delay, then the callback wont be executed until the call stack is emptied.)

Upvotes: 1

Related Questions