| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of html; | 5 part of html; |
| 6 | 6 |
| 7 typedef void _MicrotaskCallback(); | 7 typedef void _MicrotaskCallback(); |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * This class attempts to invoke a callback as soon as the current event stack | 10 * This class attempts to invoke a callback as soon as the current event stack |
| 11 * unwinds, but before the browser repaints. | 11 * unwinds, but before the browser repaints. |
| 12 */ | 12 */ |
| 13 abstract class _MicrotaskScheduler { | 13 abstract class _MicrotaskScheduler { |
| 14 bool _nextMicrotaskFrameScheduled = false; | 14 bool _nextMicrotaskFrameScheduled = false; |
| 15 _MicrotaskCallback _callback; | 15 final _MicrotaskCallback _callback; |
| 16 | 16 |
| 17 _MicrotaskScheduler(this._callback); | 17 _MicrotaskScheduler(this._callback); |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Creates the best possible microtask scheduler for the current platform. | 20 * Creates the best possible microtask scheduler for the current platform. |
| 21 */ | 21 */ |
| 22 factory _MicrotaskScheduler.best(_MicrotaskCallback callback) { | 22 factory _MicrotaskScheduler.best(_MicrotaskCallback callback) { |
| 23 if (Window._supportsSetImmediate) { | 23 if (Window._supportsSetImmediate) { |
| 24 return new _SetImmediateScheduler(callback); | 24 return new _SetImmediateScheduler(callback); |
| 25 } else if (MutationObserver.supported) { | 25 } else if (MutationObserver.supported) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 /** | 147 /** |
| 148 * Complete all pending microtasks. | 148 * Complete all pending microtasks. |
| 149 */ | 149 */ |
| 150 void _completeMicrotasks() { | 150 void _completeMicrotasks() { |
| 151 var callbacks = _pendingMicrotasks; | 151 var callbacks = _pendingMicrotasks; |
| 152 _pendingMicrotasks = null; | 152 _pendingMicrotasks = null; |
| 153 for (var callback in callbacks) { | 153 for (var callback in callbacks) { |
| 154 callback(); | 154 callback(); |
| 155 } | 155 } |
| 156 } | 156 } |
| OLD | NEW |