Skip to content

MicroTaskQueue #1224

@mhevery

Description

@mhevery

Goal

To be able to execute Promises then() in the current VM turn.

  • Design MicroTaskQueue
  • Replace native Promise with a polyfill which uses MicroTaskQueue. The polyfill must use MicroTaskQueue on resolving the Promise.
  • Because native API uses native Promises instance, we have to monkepatch native Promise.prototype.then to convert native to pol.
  • Have a MicroTaskQueueZone which captures and drains the MicroTaskQueue on VM turn end.
  • Change ChangeDetector to drain the MicroTaskQueue every time we transition to child component sub-ChangeDetector (not child ChangeDetector in the current shadow DOM, ie ForOf)

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.)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions