Re: Task Queues as a primitive

> The HTML spec speaks a lot about task queues [1]
> and "spin the event loop" [2], but there are only
> limited ways for devs to hook into those today.
>
> Would be nice if there was some primitive that
> allowed JS developers to hook into the loop without
> relying on hacks like setTimeout and MutationObserver.
>
> It would also be nice to see what is in those task queues
> (ordering, etc) and in which order the task queues are
> processed.
>
> Thoughts?

Browser will probably never let you look at what they're going to do next, 
because that would reveal much of their internal behavior, may be decided in 
function of what you're doing and how much time it took, and may change 
between releases (and therefore causing bugs if you act based on this 
information).

However, it seems it's already possible to build a JS-based priority queue 
by using the setImmediate() hook and a custom Scheduler interface, as 
demonstrated in WinJS 2.0 [1]. Basically, they're using priority bins to 
influence the order of JS-based async tasks by managing them in a scheduler 
that will act as a gateway from the native event loop to the JS waiting 
tasks.

The source code of WinJS is available but I've not downloaded the 2.0 
preview version so I can't give more insight about it (and, in particular, 
if they used any other API than setImmediate to hook into the event queue).

_______________________
[1] http://msdn.microsoft.com/en-us/library/windows/apps/dn301941.aspx 

Received on Monday, 1 July 2013 15:37:54 UTC