File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -539,6 +539,7 @@ class RootScope extends Scope {
539
539
_scopeStats)
540
540
{
541
541
_zone.onTurnDone = apply;
542
+ _zone._onScheduleMicrotask = runAsync;
542
543
_zone.onError = (e, s, ls) => _exceptionHandler (e, s);
543
544
}
544
545
@@ -666,11 +667,15 @@ class RootScope extends Scope {
666
667
667
668
// QUEUES
668
669
void runAsync (fn ()) {
669
- var chain = new _FunctionChain (fn);
670
- if (_runAsyncHead == null ) {
671
- _runAsyncHead = _runAsyncTail = chain;
670
+ if (_state == null || _state == RootScope .STATE_APPLY || _state == RootScope .STATE_DIGEST ) {
671
+ var chain = new _FunctionChain (fn);
672
+ if (_runAsyncHead == null ) {
673
+ _runAsyncHead = _runAsyncTail = chain;
674
+ } else {
675
+ _runAsyncTail = _runAsyncTail._next = chain;
676
+ }
672
677
} else {
673
- _runAsyncTail = _runAsyncTail._next = chain ;
678
+ throw "Flush phase can not schedule microtasks." ;
674
679
}
675
680
}
676
681
Original file line number Diff line number Diff line change @@ -154,17 +154,23 @@ void main() {
154
154
it ('should call onTurnDone for a scheduleMicrotask in onTurnDone' , async ((Logger log) {
155
155
var ran = false ;
156
156
zone.onTurnDone = () {
157
+ log ('onTurnDone(begin)' );
157
158
if (! ran) {
158
159
scheduleMicrotask (() { ran = true ; log ('onTurnAsync' ); });
159
160
}
160
- log ('onTurnDone' );
161
+ log ('onTurnDone(end)' );
162
+ };
163
+ zon.onSchedulMicrotask = (microTaskFn) {
164
+ log ('onScheduleMicrotask(begin)' );
165
+ microTaskFn ();
166
+ log ('onScheduleMicrotask(end)' );
161
167
};
162
168
zone.run (() {
163
169
log ('run' );
164
170
});
165
171
microLeap ();
166
172
167
- expect (log.result ()).toEqual ('onTurnStart; run; onTurnDone; onTurnStart ; onTurnAsync; onTurnDone' );
173
+ expect (log.result ()).toEqual ('onTurnStart; run; onTurnDone(begin); onScheduleMicrotask(begin) ; onTurnAsync; onScheduleMicrotask(begin); onTurnDone(end) ' );
168
174
}));
169
175
170
176
You can’t perform that action at this time.
0 commit comments