Re: Proposal: High resolution (and otherwise improved) timer API

On Oct 3, 2008, at 4:59 AM, Anne van Kesteren wrote:

> On Fri, 03 Oct 2008 05:43:55 +0200, Maciej Stachowiak  
> <mjs@apple.com> wrote:
>> - Perhaps the argument order should be (handler, delay, repeating)  
>> instead, to be more like setTimeout / setInterval
>>
>> - Perhaps the "repeating" or even the "delayInSeconds" arguments  
>> should be optional, defaulting to false and 0 respectively, and  
>> possibly in combination with the above suggestion.
>
> I think that would be nice.
>
>
> I was wondering why startTimer returns a Timer object. What is the  
> use case for that?

So you can store it and stop the timer, or reset its fire time.  
Currently, setTimeout and setInterval return an integer ID that you  
can use to cancel, which is pretty lame, and the only way to reset a  
timer to fire at a later time would be to cancel the existing timer  
(by integer ID) and have access to the original callback function.

I'm told by developers of some of Google's bigger Web apps that  
resetting a timer to wait longer is a pretty common use case. And an  
object clearly seems like a better way to represent a timer even for  
cancellation purposes than an integer ID.

Regards,
Maciej

Received on Friday, 3 October 2008 12:24:37 UTC