Chromium Code Reviews| Index: pkg/observe/lib/src/microtask.dart |
| diff --git a/pkg/observe/lib/src/microtask.dart b/pkg/observe/lib/src/microtask.dart |
| index e56fb623d6385b76ce5f785899e202b90d80624d..538d04fadba7ef72b1f76b6e09d7a49adcd56179 100644 |
| --- a/pkg/observe/lib/src/microtask.dart |
| +++ b/pkg/observe/lib/src/microtask.dart |
| @@ -11,6 +11,7 @@ |
| library observe.src.microtask; |
| import 'dart:async' show Completer, runZonedExperimental; |
| +import 'dart:collection'; |
| import 'package:observe/observe.dart' show Observable; |
| // TODO(jmesserly): remove "microtask" from these names and instead import |
| @@ -27,11 +28,11 @@ import 'package:observe/observe.dart' show Observable; |
| void performMicrotaskCheckpoint() { |
| Observable.dirtyCheck(); |
| - while (_pending.length > 0) { |
| - var pending = _pending; |
| - _pending = []; |
| + while (_pending.isNotEmpty) { |
| - for (var callback in pending) { |
| + final startLength = _pending.length; |
|
Siggi Cherem (dart-lang)
2013/08/28 19:46:51
delete (unused variable)
Jennifer Messerly
2013/08/28 19:56:04
Done.
|
| + for (int len = _pending.length; len > 0 && _pending.isNotEmpty; len--) { |
| + final callback = _pending.removeFirst(); |
| try { |
| callback(); |
| } catch (e, s) { |
| @@ -43,17 +44,21 @@ void performMicrotaskCheckpoint() { |
| } |
| } |
| -List<Function> _pending = []; |
| +final Queue<Function> _pending = new Queue<Function>(); |
| /** |
| - * Wraps the [testCase] in a zone that supports [performMicrotaskCheckpoint], |
| + * Wraps the [body] in a zone that supports [performMicrotaskCheckpoint], |
| * and returns the test case. |
| */ |
| -wrapMicrotask(void testCase()) { |
| +// TODO(jmesserly): do we want to support nested microtasks similar to nested |
| +// zones? Instead of a single pending list we'd need one per wrapMicrotask, |
| +// and [performMicrotaskCheckpoint] would only run pending callbacks |
| +// corresponding to the innermost wrapMicrotask body. |
| +wrapMicrotask(void body()) { |
| return () { |
| runZonedExperimental(() { |
| try { |
| - testCase(); |
| + body(); |
| } finally { |
| performMicrotaskCheckpoint(); |
| } |