| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /** | 5 /** |
| 6 * *Warning*: this library is **internal**, and APIs are subject to change. | 6 * *Warning*: this library is **internal**, and APIs are subject to change. |
| 7 * | 7 * |
| 8 * Wraps a callback using [wrapMicrotask] and provides the ability to pump all | 8 * Wraps a callback using [wrapMicrotask] and provides the ability to pump all |
| 9 * observable objects and [runAsync] calls via [performMicrotaskCheckpoint]. | 9 * observable objects and [scheduleMicrotask] calls via |
| 10 * [performMicrotaskCheckpoint]. |
| 10 */ | 11 */ |
| 11 library observe.src.microtask; | 12 library observe.src.microtask; |
| 12 | 13 |
| 13 import 'dart:async' show Completer, runZonedExperimental; | 14 import 'dart:async' show Completer, runZonedExperimental; |
| 14 import 'dart:collection'; | 15 import 'dart:collection'; |
| 15 import 'package:observe/observe.dart' show Observable; | 16 import 'package:observe/observe.dart' show Observable; |
| 16 | 17 |
| 17 // TODO(jmesserly): remove "microtask" from these names and instead import | 18 // TODO(jmesserly): remove "microtask" from these names and instead import |
| 18 // the library "as microtask"? | 19 // the library "as microtask"? |
| 19 | 20 |
| 20 /** | 21 /** |
| 21 * This change pumps events relevant to observers and data-binding tests. | 22 * This change pumps events relevant to observers and data-binding tests. |
| 22 * This must be used inside an [observeTest]. | 23 * This must be used inside an [observeTest]. |
| 23 * | 24 * |
| 24 * Executes all pending [runAsync] calls on the event loop, as well as | 25 * Executes all pending [scheduleMicrotask] calls on the event loop, as well as |
| 25 * performing [Observable.dirtyCheck], until there are no more pending events. | 26 * performing [Observable.dirtyCheck], until there are no more pending events. |
| 26 * It will always dirty check at least once. | 27 * It will always dirty check at least once. |
| 27 */ | 28 */ |
| 28 // TODO(jmesserly): do we want to support nested microtasks similar to nested | 29 // TODO(jmesserly): do we want to support nested microtasks similar to nested |
| 29 // zones? Instead of a single pending list we'd need one per wrapMicrotask, | 30 // zones? Instead of a single pending list we'd need one per wrapMicrotask, |
| 30 // and [performMicrotaskCheckpoint] would only run pending callbacks | 31 // and [performMicrotaskCheckpoint] would only run pending callbacks |
| 31 // corresponding to the innermost wrapMicrotask body. | 32 // corresponding to the innermost wrapMicrotask body. |
| 32 void performMicrotaskCheckpoint() { | 33 void performMicrotaskCheckpoint() { |
| 33 Observable.dirtyCheck(); | 34 Observable.dirtyCheck(); |
| 34 | 35 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 59 /** | 60 /** |
| 60 * Runs the [body] in a zone that supports [performMicrotaskCheckpoint], | 61 * Runs the [body] in a zone that supports [performMicrotaskCheckpoint], |
| 61 * and returns the result. | 62 * and returns the result. |
| 62 */ | 63 */ |
| 63 runMicrotask(body()) => runZonedExperimental(() { | 64 runMicrotask(body()) => runZonedExperimental(() { |
| 64 try { | 65 try { |
| 65 return body(); | 66 return body(); |
| 66 } finally { | 67 } finally { |
| 67 performMicrotaskCheckpoint(); | 68 performMicrotaskCheckpoint(); |
| 68 } | 69 } |
| 69 }, onRunAsync: (callback) => _pending.add(callback)); | 70 }, onScheduleMicrotask: (callback) => _pending.add(callback)); |
| OLD | NEW |