[webkit-dev] High Resolution Timer API proposal(s)
Maciej Stachowiak
mjs at apple.com
Thu Oct 2 20:19:33 PDT 2008
On Oct 2, 2008, at 6:50 PM, Aaron Boodman wrote:
> On Thu, Oct 2, 2008 at 5:05 PM, Maciej Stachowiak <mjs at apple.com>
> wrote:
>> Timer startTimer(double delayInSeconds, bool repeating, Function
>> callback);
>>
>> interface Timer {
>> void stop();
>> }
>
> One other random idea. What about mixing up the param order for
> parallelism with the existing timer APIs:
>
> Timer startTimer(Function callback, double delay, bool repeating);
>
> That would make a call look like this:
>
> var timer = startTimer(function() { ... }, 42, true);
>
> Which feels more familiar, but at the same timer better. Less new
> things to remember. Also, I think this argues for the unit to continue
> being milliseconds, again, for familiarity.
The reason I like the other parameters first is that the function
parameter could plausibly be quite long. Let's say you are writing a
big continuation function inline, to communicate work in progress via
lexically visible variables, and let's say maybe even you nest it:
startTimer(function() {
while (true) {
//do very important work
// do even more important work
}
if (important)
work();
startTimer(function() {
// do even more important work
if (doSomethingLater)
startTimer(function() {
// stuff to do later
}, 42, false);
// even stillmore important stuff
}, 0, false);
}, 0, false);
That seems pretty oogey to me.
On the other hand, I agree (as stated elsewhere in the thread) that
constantly mentioning false for non-repeating is lame. I think there
are three ways to deal with that:
1) Reorder the parameters as you have proposed and make the boolean
optional (perhaps even make the time optional too, defaulting to 0).
2) Keep the parameters in the order I proposed, but make the first
ones optional - that's a little weird, but not untenable.
3) Split the method into startTimer and startRepeatingTimer.
I think I will mention some of these possible variations when
proposing the spec. At Hixie's suggestion I will propose it as a
standalone spec on <public-webapps at w3.org>, I recommend that those who
wish to follow the discussion subscribe to that list.
Regards,
Maciej
More information about the webkit-dev
mailing list