It seems to me that the best way to do this in ES6 would be to run the call 
backs as individual Jobs (what until recently we were calling ES Tasks, 
http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tasks-and-task-queues 
).  The mechanisms are already in the ES6 spec. so that any any unhanded 
exceptions that occur in a Job are handled in the common implementation defined 
manner.

What would have to be defined would be a new ES API for adding the invocation 
of a ES function as a pending job in a job queue.  Maybe something like:

Function.prototype.callAsJob = function(...args) {
    $$EnqueueJob("UserJobs", ScriptEvaluationJob, args);  //handwave for 
calling ES internal abstraction operation
}

then notifyListners could just be:

 for (listener of listeners) {
   listener.callAsJob();
 }

and all the event handlers would be enqueue before any of them actually ran, 
which I believe is closer to what we want in terms of the ES concurrency model. 

Of course, an ES level Jobs API could include other embellishments such as 
explicitly setting an unhandled exception handler for a Job, or associating 
completion of a Job with a Promise.

Allen
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to