[webkit-dev] High Resolution Timer API proposal(s)

Ojan Vafai ojan at chromium.org
Thu Oct 2 18:14:25 PDT 2008

On Thu, Oct 2, 2008 at 5:59 PM, Maciej Stachowiak <mjs at apple.com> wrote:
> On Oct 2, 2008, at 5:28 PM, Ojan Vafai wrote:
> On Thu, Oct 2, 2008 at 5:16 PM, Aaron Boodman <aa at google.com> wrote:
>> On Thu, Oct 2, 2008 at 5:05 PM, Maciej Stachowiak <mjs at apple.com> wrote:
>> > I don't really like the overengineered version. I like the "fairly
>> > minimalist" version best, but is there anything from the
>> > overengineered version that should be added to it?
>> I like the "fairly minimalist" version best as well.
>> The stop() method does seem a little lonely on the Timer interface all
>> by itself.
>> If others think any other members from the "overengineered" version
>> are important I would welcome them to keep stop() company.
> +1. My ideal would be the following:
> Timer startTimer(double delayInSeconds, bool repeating, Function callback);
> interface Timer {
>     void stop();
>     void resume();
>     void setDelay(double delayInSeconds);
> }
> What would you expect the resume() method to do (since there is no pause)?

I guess a better name would be restart? I don't see the need for there to be
a stop and a pause. I realize they are subtley different, but not enough
that it's worth a more complicated API. In short, I would expect
restart/resume to start the timer over, as if a new timer were created.

> That would cover the majority of cases I've seen in real-world javascript
> code. The argument for setDelay is wanting to be able to tweak the delay on
> the fly (e.g. Google Page Creator has autosave code that gets a response
> from the server  with a longer delay time when the server is overloaded).
> I briefly considered cases like that, but I thought it seemed simple enough
> to just cancel the existing timer and start a new one. And it seemed
> uncommon enough to me that it didn't need a direct affordance in the API
> instead of just making a new timer.

The thing is that often enough the place where you want to modify the delay
you don't necessarily have access to the callback you would need in order to
recreate the timer. So, you have to keep track of more stuff in JavaScript
(e.g. a pointer to the callback). It's not the end of the world, but it
makes for clunkier uses of the API.

What do you think of the following?

interface Timer {
    void stop();
    void restart(double optional_argument_delayInSeconds);

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.webkit.org/pipermail/webkit-dev/attachments/20081002/4988d4e7/attachment.html 

More information about the webkit-dev mailing list