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

Maciej Stachowiak mjs at apple.com
Thu Oct 2 17:05:21 PDT 2008


I'm going to send this along to the relevant fora (not sure if it  
should be part of HTML5 or a separate Web Apps WG spec), but here's  
some rough API ideas:


Ridiculously minimalist version:

void callSoon(Function callback);

- Calls the function "callback" with no arguments the next time  
processing returns to the event loop as if it were a timer ready to  
fire.

To break up work with event processing you'd do:
callSoon(continueFunc);



Fairly minimalist version:

Timer startTimer(double delayInSeconds, bool repeating, Function  
callback);

interface Timer {
     void stop();
}


- Starts a timer that will call function "callback" after  
"delayInSeconds", which may be a fractional number of seconds. If  
"repeating" is true, the timer will fire periodically at every  
delayInSeconds. User agents should try to fire timers as close to the  
true delay time as they can, and in particular if the delay is 0 the  
timer should be considered ready to fire on the next return to the  
event loop.


To break up work with event processing you'd do:
startTimer(0, false, continueFunc);



Overengineered version:

Timer createTimer(double firstInterval, double repeatInterval, long  
repeatCount);

interface Timer : EventTarget {
     void stop();
     void start();
     void pause();
     void resume();
     readonly attribute bool isRunning;
     readonly attribute bool isPaused;
     readonly attribute Date startDate;
     double firstInterval;
     double repeatInterval;
     double timeRemaining;
     long repeatCount;
     long repeatsRemaining;
};

- fires event named "timer" when the timer is ready to fire.

To break up work with event processing you'd do:
var timer = createTimer(0, 0, 1);
timer.addEventListener("timer", continueFunc, false);
timer.start();


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'll probably propose something like the fairly minimalist version to  
HTML5.

Regards,
Maciej



More information about the webkit-dev mailing list