Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: pkg/observe/lib/src/microtask.dart

Issue 23539003: Turn on Polymer TodoMVC tests on Dart buildbots (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/polymer/build.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 [runAsync] calls via [performMicrotaskCheckpoint].
10 */ 10 */
11 library observe.src.microtask; 11 library observe.src.microtask;
12 12
13 import 'dart:async' show Completer, runZonedExperimental; 13 import 'dart:async' show Completer, runZonedExperimental;
14 import 'dart:collection';
14 import 'package:observe/observe.dart' show Observable; 15 import 'package:observe/observe.dart' show Observable;
15 16
16 // TODO(jmesserly): remove "microtask" from these names and instead import 17 // TODO(jmesserly): remove "microtask" from these names and instead import
17 // the library "as microtask"? 18 // the library "as microtask"?
18 19
19 /** 20 /**
20 * This change pumps events relevant to observers and data-binding tests. 21 * This change pumps events relevant to observers and data-binding tests.
21 * This must be used inside an [observeTest]. 22 * This must be used inside an [observeTest].
22 * 23 *
23 * Executes all pending [runAsync] calls on the event loop, as well as 24 * Executes all pending [runAsync] calls on the event loop, as well as
24 * performing [Observable.dirtyCheck], until there are no more pending events. 25 * performing [Observable.dirtyCheck], until there are no more pending events.
25 * It will always dirty check at least once. 26 * It will always dirty check at least once.
26 */ 27 */
28 // 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 // and [performMicrotaskCheckpoint] would only run pending callbacks
31 // corresponding to the innermost wrapMicrotask body.
27 void performMicrotaskCheckpoint() { 32 void performMicrotaskCheckpoint() {
28 Observable.dirtyCheck(); 33 Observable.dirtyCheck();
29 34
30 while (_pending.length > 0) { 35 while (_pending.isNotEmpty) {
31 var pending = _pending;
32 _pending = [];
33 36
34 for (var callback in pending) { 37 for (int len = _pending.length; len > 0 && _pending.isNotEmpty; len--) {
38 final callback = _pending.removeFirst();
35 try { 39 try {
36 callback(); 40 callback();
37 } catch (e, s) { 41 } catch (e, s) {
38 new Completer().completeError(e, s); 42 new Completer().completeError(e, s);
39 } 43 }
40 } 44 }
41 45
42 Observable.dirtyCheck(); 46 Observable.dirtyCheck();
43 } 47 }
44 } 48 }
45 49
46 List<Function> _pending = []; 50 final Queue<Function> _pending = new Queue<Function>();
47 51
48 /** 52 /**
49 * Wraps the [testCase] in a zone that supports [performMicrotaskCheckpoint], 53 * Wraps the [body] in a zone that supports [performMicrotaskCheckpoint],
50 * and returns the test case. 54 * and returns the body.
51 */ 55 */
52 wrapMicrotask(testCase()) { 56 // TODO(jmesserly): deprecate? this doesn't add much over runMicrotask.
53 return () { 57 wrapMicrotask(body()) => () => runMicrotask(body);
54 return runZonedExperimental(() { 58
55 try { 59 /**
56 return testCase(); 60 * Runs the [body] in a zone that supports [performMicrotaskCheckpoint],
57 } finally { 61 * and returns the result.
58 performMicrotaskCheckpoint(); 62 */
59 } 63 runMicrotask(body()) => runZonedExperimental(() {
60 }, onRunAsync: (callback) => _pending.add(callback)); 64 try {
61 }; 65 return body();
62 } 66 } finally {
67 performMicrotaskCheckpoint();
68 }
69 }, onRunAsync: (callback) => _pending.add(callback));
OLDNEW
« no previous file with comments | « no previous file | pkg/polymer/build.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698