Ron Buckton (2013-08-09T19:13:31.000Z)
domenic at domenicdenicola.com (2013-08-12T05:31:54.896Z)
For promises using microtasks, one possibility I've been experimenting with in my polyfill is a Promise.yield() method that returns a Promise that resolves after the next time the UI thread gets a chance to drain its event queue (either through requestAnimationFrame or setTimeout). While it works better with async/await or generators+trampoline, it still works with Promise#then (and Promise#flatMap). It doesn't prevent developers from writing bad code, but it does provide a way to break out of the microtask scheduler. Also, unless it breaks an invariant or expectation, would it be useful to have microtasks periodically and/or randomly yield to the event queue to allow the UI to drain its events? There could also be a (albeit probably better named) nextMicrotaskWillYield() API that could be called to have some foreknowledge as to whether future microtasks scheduled within the current microtask will be delayed until after the browser can process tasks or the event queue.