Skip to content

setZeroTimeout with functionality closer to setTimeout, without interfering with the browser's native error handler.

Notifications You must be signed in to change notification settings

shahyar/setZeroTimeout-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

setZeroTimeout is a simple utility function allowing you to use a sub-10ms (near-instantaneous, in most cases) asynchronous setTimeout analogue. This is performed using the browser's messaging system. In simpler terms: 0ms setTimeout.

Its usage is simple: setZeroTimeout(Function, 0);

It uses setTimeout syntax, because in unsupporting browsers (FF<3, IE<8, SF<5, O<10), setZeroTimeout is actually a reference to setTimeout. Therefore, the second parameter of timeout is mandatory. On most old browsers, the actual minimum for setTimeout is ~10ms. setZeroTimeout usually runs much under 1ms.

While other setZeroTimeout implementations exist, this particular one continues to throw valid Errors inside a closure, without breaking the timeout queue nor severely hindering JavaScript debuggability.

Licensed freely under CC 3.0: http://creativecommons.org/licenses/by/3.0/

--SG

About

setZeroTimeout with functionality closer to setTimeout, without interfering with the browser's native error handler.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published