Bringing setTimeout to ECMAScript
jorge at jorgechamorro.com
Sat Mar 19 14:29:45 PDT 2011
On 19/03/2011, at 17:58, Mark S. Miller wrote:
> Layering the other way, with setTimeout at the bottom, would mean the event loop could never run faster than 4ms per turn. This is unacceptable, and probably has been since the mid '70s. Should we clamp our fast our CPUs can execute instructions as well? That said, I think something like setTimeout with better semantics is the right lower layer abstraction. The two things I'd fix in this lower layer abstraction:
> * No clamping. Time runs as fast as the platform lets it run.
Of course. There are some perfectly valid reasons for wanting to spin the event loop as fast as possible... and the clamp is the only thing that forbids it. But if there were no clamp, wouldn't a setTimeout( f, 0 ) be === nextTick( f ) ?
I have always wondered about the reason to clamp (nested) setTImeout()s, why, what for ?
Is it to protect the users' mobiles/laptops batteries from event loops spinning unnecessarily fast in some badly written web pages or perhaps in some popular (and possibly botched) library ?
And if that's the reason, and if the clamp is needed/wanted/kept for that reason, what are we going to do to protect against functions that nextTick() themselves ?
And if we can't protect against nested nextTick()s, then, does it make sense to keep the protection against setTimeout()s of 0 ?
More information about the es-discuss