Re: Future feedback

On 5/14/13 10:16 AM, Jorge wrote:
> On 14/05/2013, at 16:03, Boris Zbarsky wrote:
>> On 5/14/13 9:04 AM, David Bruant wrote:
>>> http://lists.w3.org/Archives/Public/public-script-coord/2013AprJun/0167.html
>>
>> I should note that the description of the browser event loop in that message is wrong.  It does not have only two FIFO queues in the specs, or in implementations.  In particular, see task sources.
>>
>> I would be strongly opposed to specifying something that requires only two FIFO queues.
>
> So how does it look like, in pseudo code, simplified? Please :-)


Ignoring the microtask bits, which I don't fully understand, the main 
event loop looks something like this (pardon my use of 
objects-as-hashtables; replace with Set as desired, etc):

function EventLoop() {
   this.taskSources = {};
}

EventLoop.prototype = {
   selectEvent: function() {
     var taskSource;
     // Pick a task source to service, based on whatever heuristics you
     // prefer, and store it in 'taskSource'
     return taskSource.shift();
   },

   postEvent: function(taskSourceName, event) {
     if (!(taskSourceName in this.taskSources)) {
       this.taskSources[taskSourceName] = [];
     }
     this.taskSources[taskSourceName].push(event);
   },

   runLoop: function() {
     while (true) {
       var ev = this.selectEvent();
       if (ev) {
         ev();
       } else {
         // wait for some
       }
     }
   }
}

In particular, any specification can create a new task source; they're 
just named.  And FIFO ordering only holds within a task source.

-Boris

Received on Tuesday, 14 May 2013 16:31:13 UTC