Goal
To be able to execute Promises then() in the current VM turn.
MicroTaskQueue
class MicroTaskQueue {
static current:MicroTaskQueue;
runAsync(unitOfWork:Function);
drain();
}
Polyfill Promise
We need a Promise, whoes resolve/reject method enques work on MicroTaskQueue.corrent.runAsync(). The enqued function then resloves the Promise synchronously. If MicroTaskQueue.current is not defined, then use normal system Promise resolution (ie default to macro task).
MicroTaskQueueZone
We need a zone implementation which can create a new MicroTaskQueue.current for the current duration and drain it on the end and restore the value to previous state.
ChangeDetector
We need to be able to process Promises quickly, and so they should be drained MicroTaskQueue.current.draing() at the begining of entering into a new component. (Don't drain on the current component sub views, such as ForOf loops). This means that a parent component can give a promise to a child, but not the way around. This is consistent with how data is propagated, and should not cause any surprises. (Promises can be given to children but not to parents.)
Goal
To be able to execute Promises
then()in the current VM turn.MicroTaskQueuePromisewith a polyfill which usesMicroTaskQueue. The polyfill must useMicroTaskQueueon resolving thePromise.Promises instance, we have to monkepatch nativePromise.prototype.thento convert native to pol.MicroTaskQueueZonewhich captures and drains theMicroTaskQueueon VM turn end.ChangeDetectorto drain theMicroTaskQueueevery time we transition to child component sub-ChangeDetector(not childChangeDetectorin the current shadow DOM, ieForOf)MicroTaskQueuePolyfill
PromiseWe need a Promise, whoes
resolve/rejectmethod enques work onMicroTaskQueue.corrent.runAsync(). The enqued function then resloves thePromisesynchronously. IfMicroTaskQueue.currentis not defined, then use normal systemPromiseresolution (ie default to macro task).MicroTaskQueueZoneWe need a zone implementation which can create a new
MicroTaskQueue.currentfor the current duration and drain it on the end and restore the value to previous state.ChangeDetectorWe need to be able to process
Promises quickly, and so they should be drainedMicroTaskQueue.current.draing()at the begining of entering into a new component. (Don't drain on the current component sub views, such as ForOf loops). This means that a parent component can give a promise to a child, but not the way around. This is consistent with how data is propagated, and should not cause any surprises. (Promises can be given to children but not to parents.)