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

Side by Side Diff: sdk/lib/async/zone.dart

Issue 26151002: Rename runAsync to scheduleMicrotask. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add test. Created 7 years, 2 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 | « sdk/lib/async/stream_impl.dart ('k') | tests/html/events_test.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 part of dart.async; 5 part of dart.async;
6 6
7 typedef dynamic ZoneCallback(); 7 typedef dynamic ZoneCallback();
8 typedef dynamic ZoneUnaryCallback(arg); 8 typedef dynamic ZoneUnaryCallback(arg);
9 typedef dynamic ZoneBinaryCallback(arg1, arg2); 9 typedef dynamic ZoneBinaryCallback(arg1, arg2);
10 10
11 typedef dynamic HandleUncaughtErrorHandler( 11 typedef dynamic HandleUncaughtErrorHandler(
12 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace); 12 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace);
13 typedef dynamic RunHandler(Zone self, ZoneDelegate parent, Zone zone, f()); 13 typedef dynamic RunHandler(Zone self, ZoneDelegate parent, Zone zone, f());
14 typedef dynamic RunUnaryHandler( 14 typedef dynamic RunUnaryHandler(
15 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg); 15 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg);
16 typedef dynamic RunBinaryHandler( 16 typedef dynamic RunBinaryHandler(
17 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2), arg1, arg2); 17 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2), arg1, arg2);
18 typedef ZoneCallback RegisterCallbackHandler( 18 typedef ZoneCallback RegisterCallbackHandler(
19 Zone self, ZoneDelegate parent, Zone zone, f()); 19 Zone self, ZoneDelegate parent, Zone zone, f());
20 typedef ZoneUnaryCallback RegisterUnaryCallbackHandler( 20 typedef ZoneUnaryCallback RegisterUnaryCallbackHandler(
21 Zone self, ZoneDelegate parent, Zone zone, f(arg)); 21 Zone self, ZoneDelegate parent, Zone zone, f(arg));
22 typedef ZoneBinaryCallback RegisterBinaryCallbackHandler( 22 typedef ZoneBinaryCallback RegisterBinaryCallbackHandler(
23 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)); 23 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2));
24 typedef void ScheduleMicrotaskHandler( 24 typedef void ScheduleMicrotaskHandler(
25 Zone self, ZoneDelegate parent, Zone zone, f()); 25 Zone self, ZoneDelegate parent, Zone zone, f());
26 @deprecated
27 typedef void RunAsyncHandler(
28 Zone self, ZoneDelegate parent, Zone zone, f());
26 typedef Timer CreateTimerHandler( 29 typedef Timer CreateTimerHandler(
27 Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f()); 30 Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f());
28 typedef Timer CreatePeriodicTimerHandler( 31 typedef Timer CreatePeriodicTimerHandler(
29 Zone self, ZoneDelegate parent, Zone zone, 32 Zone self, ZoneDelegate parent, Zone zone,
30 Duration period, void f(Timer timer)); 33 Duration period, void f(Timer timer));
31 typedef Zone ForkHandler(Zone self, ZoneDelegate parent, Zone zone, 34 typedef Zone ForkHandler(Zone self, ZoneDelegate parent, Zone zone,
32 ZoneSpecification specification, 35 ZoneSpecification specification,
33 Map<Symbol, dynamic> zoneValues); 36 Map<Symbol, dynamic> zoneValues);
34 37
35 /** 38 /**
36 * This class provides the specification for a forked zone. 39 * This class provides the specification for a forked zone.
37 * 40 *
38 * When forking a new zone (see [Zone.fork]) one can override the default 41 * When forking a new zone (see [Zone.fork]) one can override the default
39 * behavior of the zone by providing callbacks. These callbacks must be 42 * behavior of the zone by providing callbacks. These callbacks must be
40 * given in an instance of this class. 43 * given in an instance of this class.
41 * 44 *
42 * Handlers have the same signature as the same-named methods on [Zone] but 45 * Handlers have the same signature as the same-named methods on [Zone] but
43 * receive three additional arguments: 46 * receive three additional arguments:
44 * 47 *
45 * 1. the zone the handlers are attached to (the "self" zone). 48 * 1. the zone the handlers are attached to (the "self" zone).
46 * 2. a [ZoneDelegate] to the parent zone. 49 * 2. a [ZoneDelegate] to the parent zone.
47 * 3. the zone that first received the request (before the request was 50 * 3. the zone that first received the request (before the request was
48 * bubbled up). 51 * bubbled up).
49 * 52 *
50 * Handlers can either stop propagation the request (by simply not calling the 53 * Handlers can either stop propagation the request (by simply not calling the
51 * parent handler), or forward to the parent zone, potentially modifying the 54 * parent handler), or forward to the parent zone, potentially modifying the
52 * arguments on the way. 55 * arguments on the way.
56 *
57 * *The `runAsync` handler is deprecated. Use `scheduleMicrotask` instead.*
53 */ 58 */
54 abstract class ZoneSpecification { 59 abstract class ZoneSpecification {
55 /** 60 /**
56 * Creates a specification with the provided handlers. 61 * Creates a specification with the provided handlers.
57 */ 62 */
58 const factory ZoneSpecification({ 63 const factory ZoneSpecification({
59 dynamic handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone, 64 dynamic handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone,
60 error, StackTrace stackTrace): null, 65 error, StackTrace stackTrace): null,
61 dynamic run(Zone self, ZoneDelegate parent, Zone zone, f()): null, 66 dynamic run(Zone self, ZoneDelegate parent, Zone zone, f()): null,
62 dynamic runUnary( 67 dynamic runUnary(
63 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg): null, 68 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg): null,
64 dynamic runBinary(Zone self, ZoneDelegate parent, Zone zone, 69 dynamic runBinary(Zone self, ZoneDelegate parent, Zone zone,
65 f(arg1, arg2), arg1, arg2): null, 70 f(arg1, arg2), arg1, arg2): null,
66 ZoneCallback registerCallback( 71 ZoneCallback registerCallback(
67 Zone self, ZoneDelegate parent, Zone zone, f()): null, 72 Zone self, ZoneDelegate parent, Zone zone, f()): null,
68 ZoneUnaryCallback registerUnaryCallback( 73 ZoneUnaryCallback registerUnaryCallback(
69 Zone self, ZoneDelegate parent, Zone zone, f(arg)): null, 74 Zone self, ZoneDelegate parent, Zone zone, f(arg)): null,
70 ZoneBinaryCallback registerBinaryCallback( 75 ZoneBinaryCallback registerBinaryCallback(
71 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)): null, 76 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)): null,
72 void scheduleMicrotask( 77 void scheduleMicrotask(
73 Zone self, ZoneDelegate parent, Zone zone, f()): null, 78 Zone self, ZoneDelegate parent, Zone zone, f()): null,
79 void runAsync(
80 Zone self, ZoneDelegate parent, Zone zone, f()): null,
74 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, 81 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone,
75 Duration duration, void f()): null, 82 Duration duration, void f()): null,
76 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, 83 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone,
77 Duration period, void f(Timer timer)): null, 84 Duration period, void f(Timer timer)): null,
78 Zone fork(Zone self, ZoneDelegate parent, Zone zone, 85 Zone fork(Zone self, ZoneDelegate parent, Zone zone,
79 ZoneSpecification specification, Map zoneValues): null 86 ZoneSpecification specification, Map zoneValues): null
80 }) = _ZoneSpecification; 87 }) = _ZoneSpecification;
81 88
82 /** 89 /**
83 * Creates a specification from [other] with the provided handlers overriding 90 * Creates a specification from [other] with the provided handlers overriding
84 * the ones in [other]. 91 * the ones in [other].
85 */ 92 */
86 factory ZoneSpecification.from(ZoneSpecification other, { 93 factory ZoneSpecification.from(ZoneSpecification other, {
87 dynamic handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone, 94 dynamic handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone,
88 error, StackTrace stackTrace): null, 95 error, StackTrace stackTrace): null,
89 dynamic run(Zone self, ZoneDelegate parent, Zone zone, f()): null, 96 dynamic run(Zone self, ZoneDelegate parent, Zone zone, f()): null,
90 dynamic runUnary( 97 dynamic runUnary(
91 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg): null, 98 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg): null,
92 dynamic runBinary(Zone self, ZoneDelegate parent, Zone zone, 99 dynamic runBinary(Zone self, ZoneDelegate parent, Zone zone,
93 f(arg1, arg2), arg1, arg2): null, 100 f(arg1, arg2), arg1, arg2): null,
94 ZoneCallback registerCallback( 101 ZoneCallback registerCallback(
95 Zone self, ZoneDelegate parent, Zone zone, f()): null, 102 Zone self, ZoneDelegate parent, Zone zone, f()): null,
96 ZoneUnaryCallback registerUnaryCallback( 103 ZoneUnaryCallback registerUnaryCallback(
97 Zone self, ZoneDelegate parent, Zone zone, f(arg)): null, 104 Zone self, ZoneDelegate parent, Zone zone, f(arg)): null,
98 ZoneBinaryCallback registerBinaryCallback( 105 ZoneBinaryCallback registerBinaryCallback(
99 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)): null, 106 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)): null,
100 void scheduleMicrotask( 107 void scheduleMicrotask(
101 Zone self, ZoneDelegate parent, Zone zone, f()): null, 108 Zone self, ZoneDelegate parent, Zone zone, f()): null,
109 void runAsync(
110 Zone self, ZoneDelegate parent, Zone zone, f()): null,
102 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, 111 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone,
103 Duration duration, void f()): null, 112 Duration duration, void f()): null,
104 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, 113 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone,
105 Duration period, void f(Timer timer)): null, 114 Duration period, void f(Timer timer)): null,
106 Zone fork(Zone self, ZoneDelegate parent, Zone zone, 115 Zone fork(Zone self, ZoneDelegate parent, Zone zone,
107 ZoneSpecification specification, 116 ZoneSpecification specification,
108 Map<Symbol, dynamic> zoneValues): null 117 Map<Symbol, dynamic> zoneValues): null
109 }) { 118 }) {
110 return new ZoneSpecification( 119 return new ZoneSpecification(
111 handleUncaughtError: handleUncaughtError != null 120 handleUncaughtError: handleUncaughtError != null
112 ? handleUncaughtError 121 ? handleUncaughtError
113 : other.handleUncaughtError, 122 : other.handleUncaughtError,
114 run: run != null ? run : other.run, 123 run: run != null ? run : other.run,
115 runUnary: runUnary != null ? runUnary : other.runUnary, 124 runUnary: runUnary != null ? runUnary : other.runUnary,
116 runBinary: runBinary != null ? runBinary : other.runBinary, 125 runBinary: runBinary != null ? runBinary : other.runBinary,
117 registerCallback: registerCallback != null 126 registerCallback: registerCallback != null
118 ? registerCallback 127 ? registerCallback
119 : other.registerCallback, 128 : other.registerCallback,
120 registerUnaryCallback: registerUnaryCallback != null 129 registerUnaryCallback: registerUnaryCallback != null
121 ? registerUnaryCallback 130 ? registerUnaryCallback
122 : other.registerUnaryCallback, 131 : other.registerUnaryCallback,
123 registerBinaryCallback: registerBinaryCallback != null 132 registerBinaryCallback: registerBinaryCallback != null
124 ? registerBinaryCallback 133 ? registerBinaryCallback
125 : other.registerBinaryCallback, 134 : other.registerBinaryCallback,
126 scheduleMicrotask: scheduleMicrotask != null 135 scheduleMicrotask: scheduleMicrotask != null
127 ? scheduleMicrotask 136 ? scheduleMicrotask
128 : other.scheduleMicrotask, 137 : (runAsync != null
138 ? runAsync
139 : other.scheduleMicrotask),
129 createTimer : createTimer != null ? createTimer : other.createTimer, 140 createTimer : createTimer != null ? createTimer : other.createTimer,
130 createPeriodicTimer: createPeriodicTimer != null 141 createPeriodicTimer: createPeriodicTimer != null
131 ? createPeriodicTimer 142 ? createPeriodicTimer
132 : other.createPeriodicTimer, 143 : other.createPeriodicTimer,
133 fork: fork != null ? fork : other.fork); 144 fork: fork != null ? fork : other.fork);
134 } 145 }
135 146
136 HandleUncaughtErrorHandler get handleUncaughtError; 147 HandleUncaughtErrorHandler get handleUncaughtError;
137 RunHandler get run; 148 RunHandler get run;
138 RunUnaryHandler get runUnary; 149 RunUnaryHandler get runUnary;
139 RunBinaryHandler get runBinary; 150 RunBinaryHandler get runBinary;
140 RegisterCallbackHandler get registerCallback; 151 RegisterCallbackHandler get registerCallback;
141 RegisterUnaryCallbackHandler get registerUnaryCallback; 152 RegisterUnaryCallbackHandler get registerUnaryCallback;
142 RegisterBinaryCallbackHandler get registerBinaryCallback; 153 RegisterBinaryCallbackHandler get registerBinaryCallback;
143 ScheduleMicrotaskHandler get scheduleMicrotask; 154 ScheduleMicrotaskHandler get scheduleMicrotask;
155 @deprecated
156 RunAsyncHandler get runAsync;
144 CreateTimerHandler get createTimer; 157 CreateTimerHandler get createTimer;
145 CreatePeriodicTimerHandler get createPeriodicTimer; 158 CreatePeriodicTimerHandler get createPeriodicTimer;
146 ForkHandler get fork; 159 ForkHandler get fork;
147 } 160 }
148 161
149 /** 162 /**
150 * Internal [ZoneSpecification] class. 163 * Internal [ZoneSpecification] class.
151 * 164 *
152 * The implementation wants to rely on the fact that the getters cannot change 165 * The implementation wants to rely on the fact that the getters cannot change
153 * dynamically. We thus require users to go through the redirecting 166 * dynamically. We thus require users to go through the redirecting
154 * [ZoneSpecification] constructor which instantiates this class. 167 * [ZoneSpecification] constructor which instantiates this class.
155 */ 168 */
156 class _ZoneSpecification implements ZoneSpecification { 169 class _ZoneSpecification implements ZoneSpecification {
157 const _ZoneSpecification({ 170 const _ZoneSpecification({
158 this.handleUncaughtError: null, 171 this.handleUncaughtError: null,
159 this.run: null, 172 this.run: null,
160 this.runUnary: null, 173 this.runUnary: null,
161 this.runBinary: null, 174 this.runBinary: null,
162 this.registerCallback: null, 175 this.registerCallback: null,
163 this.registerUnaryCallback: null, 176 this.registerUnaryCallback: null,
164 this.registerBinaryCallback: null, 177 this.registerBinaryCallback: null,
165 this.scheduleMicrotask: null, 178 scheduleMicrotask: null,
179 runAsync: null,
166 this.createTimer: null, 180 this.createTimer: null,
167 this.createPeriodicTimer: null, 181 this.createPeriodicTimer: null,
168 this.fork: null 182 this.fork: null
169 }); 183 }) : this.scheduleMicrotask =
184 scheduleMicrotask != null ? scheduleMicrotask : runAsync;
170 185
171 // TODO(13406): Enable types when dart2js supports it. 186 // TODO(13406): Enable types when dart2js supports it.
172 final /*HandleUncaughtErrorHandler*/ handleUncaughtError; 187 final /*HandleUncaughtErrorHandler*/ handleUncaughtError;
173 final /*RunHandler*/ run; 188 final /*RunHandler*/ run;
174 final /*RunUnaryHandler*/ runUnary; 189 final /*RunUnaryHandler*/ runUnary;
175 final /*RunBinaryHandler*/ runBinary; 190 final /*RunBinaryHandler*/ runBinary;
176 final /*RegisterCallbackHandler*/ registerCallback; 191 final /*RegisterCallbackHandler*/ registerCallback;
177 final /*RegisterUnaryCallbackHandler*/ registerUnaryCallback; 192 final /*RegisterUnaryCallbackHandler*/ registerUnaryCallback;
178 final /*RegisterBinaryCallbackHandler*/ registerBinaryCallback; 193 final /*RegisterBinaryCallbackHandler*/ registerBinaryCallback;
179 final /*ScheduleMicrotaskHandler*/ scheduleMicrotask; 194 final /*ScheduleMicrotaskHandler*/ scheduleMicrotask;
195 @deprecated
196 get runAsync => scheduleMicrotask;
180 final /*CreateTimerHandler*/ createTimer; 197 final /*CreateTimerHandler*/ createTimer;
181 final /*CreatePeriodicTimerHandler*/ createPeriodicTimer; 198 final /*CreatePeriodicTimerHandler*/ createPeriodicTimer;
182 final /*ForkHandler*/ fork; 199 final /*ForkHandler*/ fork;
183 } 200 }
184 201
185 /** 202 /**
186 * This class wraps zones for delegation. 203 * This class wraps zones for delegation.
187 * 204 *
188 * When forwarding to parent zones one can't just invoke the parent zone's 205 * When forwarding to parent zones one can't just invoke the parent zone's
189 * exposed functions (like [Zone.run]), but one needs to provide more 206 * exposed functions (like [Zone.run]), but one needs to provide more
190 * information (like the zone the `run` was initiated). Zone callbacks thus 207 * information (like the zone the `run` was initiated). Zone callbacks thus
191 * receive more information including this [ZoneDelegate] class. When delegating 208 * receive more information including this [ZoneDelegate] class. When delegating
192 * to the parent zone one should go through the given instance instead of 209 * to the parent zone one should go through the given instance instead of
193 * directly invoking the parent zone. 210 * directly invoking the parent zone.
194 */ 211 */
195 abstract class ZoneDelegate { 212 abstract class ZoneDelegate {
196 /// The [Zone] this class wraps. 213 /// The [Zone] this class wraps.
197 Zone get _zone; 214 Zone get _zone;
198 215
199 dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace); 216 dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace);
200 dynamic run(Zone zone, f()); 217 dynamic run(Zone zone, f());
201 dynamic runUnary(Zone zone, f(arg), arg); 218 dynamic runUnary(Zone zone, f(arg), arg);
202 dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2); 219 dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2);
203 ZoneCallback registerCallback(Zone zone, f()); 220 ZoneCallback registerCallback(Zone zone, f());
204 ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg)); 221 ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg));
205 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2)); 222 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2));
223 @deprecated
224 void runAsync(Zone zone, f());
206 void scheduleMicrotask(Zone zone, f()); 225 void scheduleMicrotask(Zone zone, f());
207 Timer createTimer(Zone zone, Duration duration, void f()); 226 Timer createTimer(Zone zone, Duration duration, void f());
208 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)); 227 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer));
209 Zone fork(Zone zone, ZoneSpecification specification, Map zoneValues); 228 Zone fork(Zone zone, ZoneSpecification specification, Map zoneValues);
210 } 229 }
211 230
212 /** 231 /**
213 * A Zone represents the asynchronous version of a dynamic extent. Asynchronous 232 * A Zone represents the asynchronous version of a dynamic extent. Asynchronous
214 * callbacks are executed in the zone they have been queued in. For example, 233 * callbacks are executed in the zone they have been queued in. For example,
215 * the callback of a `future.then` is executed in the same zone as the one where 234 * the callback of a `future.then` is executed in the same zone as the one where
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 * return (arg1, arg2) => thin.runBinary(registered, arg1, arg2); 366 * return (arg1, arg2) => thin.runBinary(registered, arg1, arg2);
348 */ 367 */
349 ZoneBinaryCallback bindBinaryCallback( 368 ZoneBinaryCallback bindBinaryCallback(
350 f(arg1, arg2), { bool runGuarded: true }); 369 f(arg1, arg2), { bool runGuarded: true });
351 370
352 /** 371 /**
353 * Runs [f] asynchronously. 372 * Runs [f] asynchronously.
354 */ 373 */
355 void scheduleMicrotask(void f()); 374 void scheduleMicrotask(void f());
356 375
376 @deprecated
377 void runAsync(void f());
378
357 /** 379 /**
358 * Creates a Timer where the callback is executed in this zone. 380 * Creates a Timer where the callback is executed in this zone.
359 */ 381 */
360 Timer createTimer(Duration duration, void callback()); 382 Timer createTimer(Duration duration, void callback());
361 383
362 /** 384 /**
363 * Creates a periodic Timer where the callback is executed in this zone. 385 * Creates a periodic Timer where the callback is executed in this zone.
364 */ 386 */
365 Timer createPeriodicTimer(Duration period, void callback(Timer timer)); 387 Timer createPeriodicTimer(Duration period, void callback(Timer timer));
366 388
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 473
452 void scheduleMicrotask(Zone zone, f()) { 474 void scheduleMicrotask(Zone zone, f()) {
453 _CustomizedZone parent = _degelationTarget; 475 _CustomizedZone parent = _degelationTarget;
454 while (parent._specification.scheduleMicrotask == null) { 476 while (parent._specification.scheduleMicrotask == null) {
455 parent = parent.parent; 477 parent = parent.parent;
456 } 478 }
457 _ZoneDelegate grandParent = new _ZoneDelegate(parent.parent); 479 _ZoneDelegate grandParent = new _ZoneDelegate(parent.parent);
458 (parent._specification.scheduleMicrotask)(parent, grandParent, zone, f); 480 (parent._specification.scheduleMicrotask)(parent, grandParent, zone, f);
459 } 481 }
460 482
483 @deprecated
484 void runAsync(Zone zone, f()) {
485 scheduleMicrotask(zone, f());
486 }
487
461 Timer createTimer(Zone zone, Duration duration, void f()) { 488 Timer createTimer(Zone zone, Duration duration, void f()) {
462 _CustomizedZone parent = _degelationTarget; 489 _CustomizedZone parent = _degelationTarget;
463 while (parent._specification.createTimer == null) { 490 while (parent._specification.createTimer == null) {
464 parent = parent.parent; 491 parent = parent.parent;
465 } 492 }
466 return (parent._specification.createTimer)( 493 return (parent._specification.createTimer)(
467 parent, new _ZoneDelegate(parent.parent), zone, duration, f); 494 parent, new _ZoneDelegate(parent.parent), zone, duration, f);
468 } 495 }
469 496
470 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)) { 497 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)) {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 } 628 }
602 629
603 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) { 630 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) {
604 return new _ZoneDelegate(this).registerBinaryCallback(this, f); 631 return new _ZoneDelegate(this).registerBinaryCallback(this, f);
605 } 632 }
606 633
607 void scheduleMicrotask(void f()) { 634 void scheduleMicrotask(void f()) {
608 new _ZoneDelegate(this).scheduleMicrotask(this, f); 635 new _ZoneDelegate(this).scheduleMicrotask(this, f);
609 } 636 }
610 637
638 @deprecated
639 void runAsync(void f()) {
640 scheduleMicrotask(f);
641 }
642
611 Timer createTimer(Duration duration, void f()) { 643 Timer createTimer(Duration duration, void f()) {
612 return new _ZoneDelegate(this).createTimer(this, duration, f); 644 return new _ZoneDelegate(this).createTimer(this, duration, f);
613 } 645 }
614 646
615 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) { 647 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) {
616 return new _ZoneDelegate(this).createPeriodicTimer(this, duration, f); 648 return new _ZoneDelegate(this).createPeriodicTimer(this, duration, f);
617 } 649 }
618 } 650 }
619 651
620 void _rootHandleUncaughtError( 652 void _rootHandleUncaughtError(
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 if (onError != null) { 830 if (onError != null) {
799 return zone.runGuarded(body); 831 return zone.runGuarded(body);
800 } else { 832 } else {
801 return zone.run(body); 833 return zone.run(body);
802 } 834 }
803 } 835 }
804 836
805 /** 837 /**
806 * Deprecated. Use `runZoned` instead or create your own [ZoneSpecification]. 838 * Deprecated. Use `runZoned` instead or create your own [ZoneSpecification].
807 * 839 *
808 * The [onRunAsync] handler (if non-null) is invoked when the [body] executes 840 * The [onScheduleMicrotask] handler (if non-null) is invoked when the [body]
809 * [runAsync]. The handler is invoked in the outer zone and can therefore 841 * executes [scheduleMicrotask]. The handler is invoked in the outer zone and
810 * execute [runAsync] without recursing. The given callback must be 842 * can therefore execute [scheduleMicrotask] without recursing. The given
811 * executed eventually. Otherwise the nested zone will not complete. It must be 843 * callback must be executed eventually. Otherwise the nested zone will not
812 * executed only once. 844 * complete. It must be executed only once.
813 * 845 *
814 * The following example prints the stack trace whenever a callback is 846 * The following example prints the stack trace whenever a callback is
815 * registered using [runAsync] (which is also used by [Completer]s and 847 * registered using [scheduleMicrotask] (which is also used by [Completer]s and
816 * [StreamController]s. 848 * [StreamController]s.
817 * 849 *
818 * printStackTrace() { try { throw 0; } catch(e, s) { print(s); } } 850 * printStackTrace() { try { throw 0; } catch(e, s) { print(s); } }
819 * runZonedExperimental(body, onRunAsync: (callback) { 851 * runZonedExperimental(body, onRunAsync: (callback) {
820 * printStackTrace(); 852 * printStackTrace();
821 * runAsync(callback); 853 * scheduleMicrotask(callback);
822 * }); 854 * });
823 * 855 *
824 * Note: the `onDone` handler is ignored. 856 * Note: the `onDone` handler is ignored.
825 */ 857 */
826 @deprecated 858 @deprecated
827 runZonedExperimental(body(), 859 runZonedExperimental(body(),
828 { void onRunAsync(void callback()), 860 { void onRunAsync(void callback()),
829 void onError(error), 861 void onError(error),
830 void onDone() }) { 862 void onDone() }) {
831 if (onRunAsync == null) { 863 if (onRunAsync == null) {
(...skipping 15 matching lines...) Expand all
847 }; 879 };
848 } 880 }
849 ScheduleMicrotaskHandler asyncHandler; 881 ScheduleMicrotaskHandler asyncHandler;
850 if (onRunAsync != null) { 882 if (onRunAsync != null) {
851 asyncHandler = (Zone self, ZoneDelegate parent, Zone zone, f()) { 883 asyncHandler = (Zone self, ZoneDelegate parent, Zone zone, f()) {
852 self.parent.runUnary(onRunAsync, () => zone.runGuarded(f)); 884 self.parent.runUnary(onRunAsync, () => zone.runGuarded(f));
853 }; 885 };
854 } 886 }
855 ZoneSpecification specification = 887 ZoneSpecification specification =
856 new ZoneSpecification(handleUncaughtError: errorHandler, 888 new ZoneSpecification(handleUncaughtError: errorHandler,
857 scheduleMicrotask: asyncHandler); 889 scheduleMicrotask: asyncHandler);
858 Zone zone = Zone.current.fork(specification: specification); 890 Zone zone = Zone.current.fork(specification: specification);
859 if (onError != null) { 891 if (onError != null) {
860 return zone.runGuarded(body); 892 return zone.runGuarded(body);
861 } else { 893 } else {
862 return zone.run(body); 894 return zone.run(body);
863 } 895 }
864 } 896 }
OLDNEW
« no previous file with comments | « sdk/lib/async/stream_impl.dart ('k') | tests/html/events_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698