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 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 Task TaskCreate(TaskSpecification taskSpecification, Zone zone); | |
Lasse Reichstein Nielsen
2016/04/01 21:26:35
Which zone are we passing to the create function?
floitsch
2016/04/05 20:07:17
The zone in which the task should execute, when th
| |
12 typedef void TaskCancel(Task task, Zone zone); | |
13 typedef void TaskRun(Task task, Object arg, Zone zone); | |
14 | |
11 typedef dynamic HandleUncaughtErrorHandler( | 15 typedef dynamic HandleUncaughtErrorHandler( |
12 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace); | 16 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace); |
13 typedef dynamic RunHandler(Zone self, ZoneDelegate parent, Zone zone, f()); | 17 typedef dynamic RunHandler(Zone self, ZoneDelegate parent, Zone zone, f()); |
14 typedef dynamic RunUnaryHandler( | 18 typedef dynamic RunUnaryHandler( |
15 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg); | 19 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg); |
16 typedef dynamic RunBinaryHandler( | 20 typedef dynamic RunBinaryHandler( |
17 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2), arg1, arg2); | 21 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2), arg1, arg2); |
18 typedef ZoneCallback RegisterCallbackHandler( | 22 typedef ZoneCallback RegisterCallbackHandler( |
19 Zone self, ZoneDelegate parent, Zone zone, f()); | 23 Zone self, ZoneDelegate parent, Zone zone, f()); |
20 typedef ZoneUnaryCallback RegisterUnaryCallbackHandler( | 24 typedef ZoneUnaryCallback RegisterUnaryCallbackHandler( |
21 Zone self, ZoneDelegate parent, Zone zone, f(arg)); | 25 Zone self, ZoneDelegate parent, Zone zone, f(arg)); |
22 typedef ZoneBinaryCallback RegisterBinaryCallbackHandler( | 26 typedef ZoneBinaryCallback RegisterBinaryCallbackHandler( |
23 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)); | 27 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)); |
24 typedef AsyncError ErrorCallbackHandler(Zone self, ZoneDelegate parent, | 28 typedef AsyncError ErrorCallbackHandler(Zone self, ZoneDelegate parent, |
25 Zone zone, Object error, StackTrace stackTrace); | 29 Zone zone, Object error, StackTrace stackTrace); |
30 typedef Task CreateTaskHandler(Zone self, ZoneDelegate parent, Zone zone, | |
31 TaskSpecification taskSpecification, TaskCreate schedule); | |
32 typedef void CancelTaskHandler(Zone self, ZoneDelegate parent, Zone zone, | |
33 Task task, TaskCancel cancel); | |
34 typedef void RunTaskHandler(Zone self, ZoneDelegate parent, Zone zone, | |
35 Task task, Object arg1, TaskRun run); | |
26 typedef void ScheduleMicrotaskHandler( | 36 typedef void ScheduleMicrotaskHandler( |
27 Zone self, ZoneDelegate parent, Zone zone, f()); | 37 Zone self, ZoneDelegate parent, Zone zone, f()); |
28 typedef Timer CreateTimerHandler( | |
29 Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f()); | |
30 typedef Timer CreatePeriodicTimerHandler( | |
31 Zone self, ZoneDelegate parent, Zone zone, | |
32 Duration period, void f(Timer timer)); | |
33 typedef void PrintHandler( | 38 typedef void PrintHandler( |
34 Zone self, ZoneDelegate parent, Zone zone, String line); | 39 Zone self, ZoneDelegate parent, Zone zone, String line); |
35 typedef Zone ForkHandler(Zone self, ZoneDelegate parent, Zone zone, | 40 typedef Zone ForkHandler(Zone self, ZoneDelegate parent, Zone zone, |
36 ZoneSpecification specification, | 41 ZoneSpecification specification, |
37 Map zoneValues); | 42 Map zoneValues); |
38 | 43 |
44 // Typedefs for deprecated methods. | |
45 typedef Timer CreateTimerHandler( | |
46 Zone self, ZoneDelegate parent, Zone zone, Duration duration, void f()); | |
47 typedef Timer CreatePeriodicTimerHandler( | |
48 Zone self, ZoneDelegate parent, Zone zone, | |
49 Duration period, void f(Timer timer)); | |
50 | |
39 /** Pair of error and stack trace. Returned by [Zone.errorCallback]. */ | 51 /** Pair of error and stack trace. Returned by [Zone.errorCallback]. */ |
40 class AsyncError implements Error { | 52 class AsyncError implements Error { |
41 final error; | 53 final error; |
42 final StackTrace stackTrace; | 54 final StackTrace stackTrace; |
43 | 55 |
44 AsyncError(this.error, this.stackTrace); | 56 AsyncError(this.error, this.stackTrace); |
45 | 57 |
46 String toString() => '$error'; | 58 String toString() => '$error'; |
47 } | 59 } |
48 | 60 |
61 /// A token-like object that represents an asynchronous operation. | |
62 /// | |
63 /// Tasks are always invoked by the event loop. For example, a [Timer] contains | |
64 /// a [Task] object that represents the scheduled operation. | |
65 /// | |
66 /// Tasks can be thought as advanced tokens (containing the task specification), | |
67 /// and aren't necessarily distributed to users. | |
68 abstract class Task { | |
69 /// The specification that was used to create this task. | |
70 TaskSpecification get specification; | |
71 | |
72 /// The zone in which the tasks has been created and should run whenever the | |
73 /// event loop runs the task. | |
74 Zone get zone; | |
floitsch
2016/03/31 19:18:01
We could remove this field.
Lasse Reichstein Nielsen
2016/04/01 21:26:35
Agree. I generally prefer not to leak zones, so co
floitsch
2016/04/05 20:07:17
The thing is, that the task needs to keep track of
| |
75 } | |
76 | |
77 abstract class TaskSpecification { | |
78 /// Description of the task. | |
79 /// | |
80 /// This string is unused by the root-zone, but might be used for debugging, | |
81 /// and testing. As such, it should be relatively unique in its category. | |
82 String get description; | |
83 | |
84 /// Whether this specification is for an event task. | |
85 /// | |
86 /// Event tasks are macro tasks with specific expectations. In particular, | |
87 /// they may never run, or run multiple times. | |
Lasse Reichstein Nielsen
2016/04/01 21:26:35
That's rather the absence of specific expectations
floitsch
2016/04/05 20:07:17
Fair enough. It might be more interesting to have
| |
88 /// | |
89 /// Event tasks are never [isOneShot]. | |
90 /// | |
91 /// Event tasks imply [isMacroTask]. | |
92 bool get isEventTask; | |
93 | |
94 /// Whether this specification is for a macro task. | |
95 /// | |
96 /// Macro tasks are triggered from the event loop and start a new micro task | |
Lasse Reichstein Nielsen
2016/04/01 21:26:35
"triggered from the event loop" is vague (as in: I
floitsch
2016/04/05 20:07:16
Done.
| |
97 /// loop. | |
98 bool get isMacroTask; | |
99 | |
100 /// Whether the scheduled task triggers at most once. | |
101 /// | |
102 /// If the task is not a one-shot task, it must be canceled. | |
Lasse Reichstein Nielsen
2016/04/01 21:26:35
"must be canceled" may be too strong. You can prob
floitsch
2016/04/05 20:07:16
Done.
| |
103 bool get isOneShot; | |
104 } | |
105 | |
106 class _TimerTaskWrapper implements Timer { | |
107 final TimerTask _task; | |
108 | |
109 _TimerTaskWrapper(this._task); | |
110 | |
111 static _cancel(TimerTask task, Zone zone) { | |
112 task.timer.cancel(); | |
113 } | |
114 | |
115 void cancel() { | |
116 _task.zone.cancelTask(_task, _cancel); | |
117 } | |
118 | |
119 bool get isActive => _task.timer.isActive; | |
120 } | |
121 | |
122 abstract class TimerTask implements Task { | |
123 final TaskSpecification specification; | |
124 final Zone zone; | |
125 /// The native timer. | |
126 final Timer timer; | |
127 | |
128 TimerTask(this.timer, this.specification, this.zone); | |
129 } | |
130 | |
131 class SingleShotTimerTask extends TimerTask { | |
132 final ZoneCallback callback; | |
133 | |
134 SingleShotTimerTask(Timer timer, this.callback, | |
135 TaskSpecification specification, Zone zone) | |
136 : super(timer, specification, zone); | |
137 } | |
138 | |
139 class PeriodicTimerTask extends TimerTask { | |
140 final ZoneUnaryCallback callback; | |
141 | |
142 PeriodicTimerTask(Timer timer, this.callback, | |
143 TaskSpecification specification, Zone zone) | |
144 : super(timer, specification, zone); | |
145 } | |
146 | |
147 class SingleShotTimerTaskSpecification implements TaskSpecification { | |
148 String get description => "Timer"; | |
Lasse Reichstein Nielsen
2016/04/01 21:26:35
Maybe just make this the "toString" of the task-sp
floitsch
2016/04/05 20:07:16
This is the identifier that delegates use to inter
| |
149 bool get isOneShot => true; | |
150 bool get isEventTask => false; | |
151 bool get isMacroTask => true; | |
152 | |
153 final Duration duration; | |
154 final ZoneCallback callback; | |
155 | |
156 SingleShotTimerTaskSpecification(this.duration, void this.callback()); | |
157 } | |
158 | |
159 class PeriodicTimerTaskSpecification implements TaskSpecification { | |
160 String get description => "Periodic Timer"; | |
161 bool get isOneShot => false; | |
162 bool get isEventTask => false; | |
163 bool get isMacroTask => true; | |
Lasse Reichstein Nielsen
2016/04/01 21:26:35
I still prefer putting getters after the construct
floitsch
2016/04/05 20:07:16
Done.
| |
164 | |
165 final Duration duration; | |
166 final ZoneUnaryCallback callback; | |
167 | |
168 PeriodicTimerTaskSpecification( | |
169 this.duration, void this.callback(Timer timer)); | |
170 } | |
49 | 171 |
50 class _ZoneFunction { | 172 class _ZoneFunction { |
51 final _Zone zone; | 173 final _Zone zone; |
52 final Function function; | 174 final Function function; |
53 const _ZoneFunction(this.zone, this.function); | 175 const _ZoneFunction(this.zone, this.function); |
54 } | 176 } |
55 | 177 |
56 /** | 178 /** |
57 * This class provides the specification for a forked zone. | 179 * This class provides the specification for a forked zone. |
58 * | 180 * |
(...skipping 28 matching lines...) Expand all Loading... | |
87 ZoneCallback registerCallback( | 209 ZoneCallback registerCallback( |
88 Zone self, ZoneDelegate parent, Zone zone, f()), | 210 Zone self, ZoneDelegate parent, Zone zone, f()), |
89 ZoneUnaryCallback registerUnaryCallback( | 211 ZoneUnaryCallback registerUnaryCallback( |
90 Zone self, ZoneDelegate parent, Zone zone, f(arg)), | 212 Zone self, ZoneDelegate parent, Zone zone, f(arg)), |
91 ZoneBinaryCallback registerBinaryCallback( | 213 ZoneBinaryCallback registerBinaryCallback( |
92 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)), | 214 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)), |
93 AsyncError errorCallback(Zone self, ZoneDelegate parent, Zone zone, | 215 AsyncError errorCallback(Zone self, ZoneDelegate parent, Zone zone, |
94 Object error, StackTrace stackTrace), | 216 Object error, StackTrace stackTrace), |
95 void scheduleMicrotask( | 217 void scheduleMicrotask( |
96 Zone self, ZoneDelegate parent, Zone zone, f()), | 218 Zone self, ZoneDelegate parent, Zone zone, f()), |
219 Task createTask(Zone self, ZoneDelegate parent, Zone zone, | |
220 TaskSpecification taskSpecification, TaskCreate create), | |
Lasse Reichstein Nielsen
2016/04/01 21:26:35
I'm still not sure I think the create argument is
floitsch
2016/04/05 20:07:16
I strongly disagree.
The root-zone must be able to
| |
221 void runTask(Zone self, ZoneDelegate parent, Zone zone, Task task, | |
222 Object arg, TaskRun run), | |
223 void cancelTask(Zone self, ZoneDelegate parent, Zone zone, Task task, | |
224 TaskCancel cancel), | |
225 | |
226 void print(Zone self, ZoneDelegate parent, Zone zone, String line), | |
227 Zone fork(Zone self, ZoneDelegate parent, Zone zone, | |
228 ZoneSpecification specification, Map zoneValues), | |
229 | |
230 @deprecated | |
97 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, | 231 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, |
98 Duration duration, void f()), | 232 Duration duration, void f()), |
233 @deprecated | |
99 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, | 234 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, |
100 Duration period, void f(Timer timer)), | 235 Duration period, void f(Timer timer)) |
101 void print(Zone self, ZoneDelegate parent, Zone zone, String line), | |
102 Zone fork(Zone self, ZoneDelegate parent, Zone zone, | |
103 ZoneSpecification specification, Map zoneValues) | |
104 }) = _ZoneSpecification; | 236 }) = _ZoneSpecification; |
105 | 237 |
106 /** | 238 /** |
107 * Creates a specification from [other] with the provided handlers overriding | 239 * Creates a specification from [other] with the provided handlers overriding |
108 * the ones in [other]. | 240 * the ones in [other]. |
109 */ | 241 */ |
110 factory ZoneSpecification.from(ZoneSpecification other, { | 242 factory ZoneSpecification.from(ZoneSpecification other, { |
111 dynamic handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone, | 243 dynamic handleUncaughtError(Zone self, ZoneDelegate parent, Zone zone, |
112 error, StackTrace stackTrace): null, | 244 error, StackTrace stackTrace): null, |
113 dynamic run(Zone self, ZoneDelegate parent, Zone zone, f()): null, | 245 dynamic run(Zone self, ZoneDelegate parent, Zone zone, f()): null, |
114 dynamic runUnary( | 246 dynamic runUnary( |
115 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg): null, | 247 Zone self, ZoneDelegate parent, Zone zone, f(arg), arg): null, |
116 dynamic runBinary(Zone self, ZoneDelegate parent, Zone zone, | 248 dynamic runBinary(Zone self, ZoneDelegate parent, Zone zone, |
117 f(arg1, arg2), arg1, arg2): null, | 249 f(arg1, arg2), arg1, arg2): null, |
118 ZoneCallback registerCallback( | 250 ZoneCallback registerCallback( |
119 Zone self, ZoneDelegate parent, Zone zone, f()): null, | 251 Zone self, ZoneDelegate parent, Zone zone, f()): null, |
120 ZoneUnaryCallback registerUnaryCallback( | 252 ZoneUnaryCallback registerUnaryCallback( |
121 Zone self, ZoneDelegate parent, Zone zone, f(arg)): null, | 253 Zone self, ZoneDelegate parent, Zone zone, f(arg)): null, |
122 ZoneBinaryCallback registerBinaryCallback( | 254 ZoneBinaryCallback registerBinaryCallback( |
123 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)): null, | 255 Zone self, ZoneDelegate parent, Zone zone, f(arg1, arg2)): null, |
124 AsyncError errorCallback(Zone self, ZoneDelegate parent, Zone zone, | 256 AsyncError errorCallback(Zone self, ZoneDelegate parent, Zone zone, |
125 Object error, StackTrace stackTrace), | 257 Object error, StackTrace stackTrace), |
126 void scheduleMicrotask( | 258 void scheduleMicrotask( |
127 Zone self, ZoneDelegate parent, Zone zone, f()): null, | 259 Zone self, ZoneDelegate parent, Zone zone, f()): null, |
128 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, | 260 |
129 Duration duration, void f()): null, | 261 Task createTask(Zone self, ZoneDelegate parent, Zone zone, |
130 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, | 262 TaskSpecification taskSpecification, TaskCreate create): null, |
131 Duration period, void f(Timer timer)): null, | 263 void runTask(Zone self, ZoneDelegate parent, Zone zone, Task task, |
264 TaskRun run): null, | |
265 void cancelTask(Zone self, ZoneDelegate parent, Zone zone, Task task, | |
266 TaskCancel cancel): null, | |
267 | |
132 void print(Zone self, ZoneDelegate parent, Zone zone, String line): null, | 268 void print(Zone self, ZoneDelegate parent, Zone zone, String line): null, |
133 Zone fork(Zone self, ZoneDelegate parent, Zone zone, | 269 Zone fork(Zone self, ZoneDelegate parent, Zone zone, |
134 ZoneSpecification specification, | 270 ZoneSpecification specification, |
135 Map zoneValues): null | 271 Map zoneValues): null, |
272 | |
273 @deprecated | |
274 Timer createTimer(Zone self, ZoneDelegate parent, Zone zone, | |
275 Duration duration, void f()): null, | |
276 @deprecated | |
277 Timer createPeriodicTimer(Zone self, ZoneDelegate parent, Zone zone, | |
278 Duration period, void f(Timer timer)): null | |
136 }) { | 279 }) { |
137 return new ZoneSpecification( | 280 return new ZoneSpecification( |
138 handleUncaughtError: handleUncaughtError ?? other.handleUncaughtError, | 281 handleUncaughtError: handleUncaughtError ?? other.handleUncaughtError, |
139 run: run ?? other.run, | 282 run: run ?? other.run, |
140 runUnary: runUnary ?? other.runUnary, | 283 runUnary: runUnary ?? other.runUnary, |
141 runBinary: runBinary ?? other.runBinary, | 284 runBinary: runBinary ?? other.runBinary, |
142 registerCallback: registerCallback ?? other.registerCallback, | 285 registerCallback: registerCallback ?? other.registerCallback, |
143 registerUnaryCallback: registerUnaryCallback ?? | 286 registerUnaryCallback: registerUnaryCallback ?? |
144 other.registerUnaryCallback, | 287 other.registerUnaryCallback, |
145 registerBinaryCallback: registerBinaryCallback ?? | 288 registerBinaryCallback: registerBinaryCallback ?? |
146 other.registerBinaryCallback, | 289 other.registerBinaryCallback, |
147 errorCallback: errorCallback ?? other.errorCallback, | 290 errorCallback: errorCallback ?? other.errorCallback, |
291 | |
292 createTask: createTask ?? other.createTask, | |
293 runTask: runTask ?? other.runTask, | |
294 cancelTask: cancelTask ?? other.cancelTask, | |
295 print : print ?? other.print, | |
296 fork: fork ?? other.fork, | |
148 scheduleMicrotask: scheduleMicrotask ?? other.scheduleMicrotask, | 297 scheduleMicrotask: scheduleMicrotask ?? other.scheduleMicrotask, |
149 createTimer : createTimer ?? other.createTimer, | 298 createTimer : createTimer ?? other.createTimer, |
150 createPeriodicTimer: createPeriodicTimer ?? other.createPeriodicTimer, | 299 createPeriodicTimer: createPeriodicTimer ?? other.createPeriodicTimer); |
151 print : print ?? other.print, | |
152 fork: fork ?? other.fork); | |
153 } | 300 } |
154 | 301 |
155 HandleUncaughtErrorHandler get handleUncaughtError; | 302 HandleUncaughtErrorHandler get handleUncaughtError; |
156 RunHandler get run; | 303 RunHandler get run; |
157 RunUnaryHandler get runUnary; | 304 RunUnaryHandler get runUnary; |
158 RunBinaryHandler get runBinary; | 305 RunBinaryHandler get runBinary; |
159 RegisterCallbackHandler get registerCallback; | 306 RegisterCallbackHandler get registerCallback; |
160 RegisterUnaryCallbackHandler get registerUnaryCallback; | 307 RegisterUnaryCallbackHandler get registerUnaryCallback; |
161 RegisterBinaryCallbackHandler get registerBinaryCallback; | 308 RegisterBinaryCallbackHandler get registerBinaryCallback; |
162 ErrorCallbackHandler get errorCallback; | 309 ErrorCallbackHandler get errorCallback; |
163 ScheduleMicrotaskHandler get scheduleMicrotask; | 310 ScheduleMicrotaskHandler get scheduleMicrotask; |
164 CreateTimerHandler get createTimer; | 311 CreateTaskHandler get createTask; |
165 CreatePeriodicTimerHandler get createPeriodicTimer; | 312 RunTaskHandler get runTask; |
313 CancelTaskHandler get cancelTask; | |
166 PrintHandler get print; | 314 PrintHandler get print; |
167 ForkHandler get fork; | 315 ForkHandler get fork; |
316 | |
317 @deprecated | |
318 CreateTimerHandler get createTimer; | |
319 @deprecated | |
320 CreatePeriodicTimerHandler get createPeriodicTimer; | |
168 } | 321 } |
169 | 322 |
170 /** | 323 /** |
171 * Internal [ZoneSpecification] class. | 324 * Internal [ZoneSpecification] class. |
172 * | 325 * |
173 * The implementation wants to rely on the fact that the getters cannot change | 326 * The implementation wants to rely on the fact that the getters cannot change |
174 * dynamically. We thus require users to go through the redirecting | 327 * dynamically. We thus require users to go through the redirecting |
175 * [ZoneSpecification] constructor which instantiates this class. | 328 * [ZoneSpecification] constructor which instantiates this class. |
176 */ | 329 */ |
177 class _ZoneSpecification implements ZoneSpecification { | 330 class _ZoneSpecification implements ZoneSpecification { |
178 const _ZoneSpecification({ | 331 const _ZoneSpecification({ |
179 this.handleUncaughtError: null, | 332 this.handleUncaughtError: null, |
180 this.run: null, | 333 this.run: null, |
181 this.runUnary: null, | 334 this.runUnary: null, |
182 this.runBinary: null, | 335 this.runBinary: null, |
183 this.registerCallback: null, | 336 this.registerCallback: null, |
184 this.registerUnaryCallback: null, | 337 this.registerUnaryCallback: null, |
185 this.registerBinaryCallback: null, | 338 this.registerBinaryCallback: null, |
186 this.errorCallback: null, | 339 this.errorCallback: null, |
187 this.scheduleMicrotask: null, | 340 this.scheduleMicrotask: null, |
341 this.createTask: null, | |
342 this.runTask: null, | |
343 this.cancelTask: null, | |
344 this.print: null, | |
345 this.fork: null, | |
346 @deprecated | |
188 this.createTimer: null, | 347 this.createTimer: null, |
189 this.createPeriodicTimer: null, | 348 @deprecated |
190 this.print: null, | 349 this.createPeriodicTimer: null |
191 this.fork: null | |
192 }); | 350 }); |
193 | 351 |
194 final HandleUncaughtErrorHandler handleUncaughtError; | 352 final HandleUncaughtErrorHandler handleUncaughtError; |
195 final RunHandler run; | 353 final RunHandler run; |
196 final RunUnaryHandler runUnary; | 354 final RunUnaryHandler runUnary; |
197 final RunBinaryHandler runBinary; | 355 final RunBinaryHandler runBinary; |
198 final RegisterCallbackHandler registerCallback; | 356 final RegisterCallbackHandler registerCallback; |
199 final RegisterUnaryCallbackHandler registerUnaryCallback; | 357 final RegisterUnaryCallbackHandler registerUnaryCallback; |
200 final RegisterBinaryCallbackHandler registerBinaryCallback; | 358 final RegisterBinaryCallbackHandler registerBinaryCallback; |
201 final ErrorCallbackHandler errorCallback; | 359 final ErrorCallbackHandler errorCallback; |
202 final ScheduleMicrotaskHandler scheduleMicrotask; | 360 final ScheduleMicrotaskHandler scheduleMicrotask; |
203 final CreateTimerHandler createTimer; | 361 final CreateTaskHandler createTask; |
204 final CreatePeriodicTimerHandler createPeriodicTimer; | 362 final RunTaskHandler runTask; |
363 final CancelTaskHandler cancelTask; | |
205 final PrintHandler print; | 364 final PrintHandler print; |
206 final ForkHandler fork; | 365 final ForkHandler fork; |
366 | |
367 @deprecated | |
368 final CreateTimerHandler createTimer; | |
369 @deprecated | |
370 final CreatePeriodicTimerHandler createPeriodicTimer; | |
207 } | 371 } |
208 | 372 |
209 /** | 373 /** |
210 * This class wraps zones for delegation. | 374 * This class wraps zones for delegation. |
211 * | 375 * |
212 * When forwarding to parent zones one can't just invoke the parent zone's | 376 * When forwarding to parent zones one can't just invoke the parent zone's |
213 * exposed functions (like [Zone.run]), but one needs to provide more | 377 * exposed functions (like [Zone.run]), but one needs to provide more |
214 * information (like the zone the `run` was initiated). Zone callbacks thus | 378 * information (like the zone the `run` was initiated). Zone callbacks thus |
215 * receive more information including this [ZoneDelegate] class. When delegating | 379 * receive more information including this [ZoneDelegate] class. When delegating |
216 * to the parent zone one should go through the given instance instead of | 380 * to the parent zone one should go through the given instance instead of |
217 * directly invoking the parent zone. | 381 * directly invoking the parent zone. |
218 */ | 382 */ |
219 abstract class ZoneDelegate { | 383 abstract class ZoneDelegate { |
220 dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace); | 384 dynamic handleUncaughtError(Zone zone, error, StackTrace stackTrace); |
221 dynamic run(Zone zone, f()); | 385 dynamic run(Zone zone, f()); |
222 dynamic runUnary(Zone zone, f(arg), arg); | 386 dynamic runUnary(Zone zone, f(arg), arg); |
223 dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2); | 387 dynamic runBinary(Zone zone, f(arg1, arg2), arg1, arg2); |
224 ZoneCallback registerCallback(Zone zone, f()); | 388 ZoneCallback registerCallback(Zone zone, f()); |
225 ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg)); | 389 ZoneUnaryCallback registerUnaryCallback(Zone zone, f(arg)); |
226 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2)); | 390 ZoneBinaryCallback registerBinaryCallback(Zone zone, f(arg1, arg2)); |
227 AsyncError errorCallback(Zone zone, Object error, StackTrace stackTrace); | 391 AsyncError errorCallback(Zone zone, Object error, StackTrace stackTrace); |
228 void scheduleMicrotask(Zone zone, f()); | 392 void scheduleMicrotask(Zone zone, f()); |
229 Timer createTimer(Zone zone, Duration duration, void f()); | 393 Task createTask(Zone zone, TaskSpecification task, TaskCreate schedule); |
230 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)); | 394 void runTask(Zone zone, Task task, Object arg, TaskRun run); |
395 void cancelTask(Zone zone, Task task, TaskCancel cancel); | |
231 void print(Zone zone, String line); | 396 void print(Zone zone, String line); |
232 Zone fork(Zone zone, ZoneSpecification specification, Map zoneValues); | 397 Zone fork(Zone zone, ZoneSpecification specification, Map zoneValues); |
398 | |
399 @deprecated | |
400 Timer createTimer(Zone zone, Duration duration, void f()); | |
401 @deprecated | |
402 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)); | |
233 } | 403 } |
234 | 404 |
235 /** | 405 /** |
236 * A Zone represents the asynchronous version of a dynamic extent. Asynchronous | 406 * A Zone represents the asynchronous version of a dynamic extent. Asynchronous |
237 * callbacks are executed in the zone they have been queued in. For example, | 407 * callbacks are executed in the zone they have been queued in. For example, |
238 * the callback of a `future.then` is executed in the same zone as the one where | 408 * the callback of a `future.then` is executed in the same zone as the one where |
239 * the `then` was invoked. | 409 * the `then` was invoked. |
240 */ | 410 */ |
241 abstract class Zone { | 411 abstract class Zone { |
242 // Private constructor so that it is not possible instantiate a Zone class. | 412 // Private constructor so that it is not possible instantiate a Zone class. |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
406 * the new pair of error and stack trace. | 576 * the new pair of error and stack trace. |
407 * If the [AsyncError.error] is `null`, it is replaced by a [NullThrownError]. | 577 * If the [AsyncError.error] is `null`, it is replaced by a [NullThrownError]. |
408 */ | 578 */ |
409 AsyncError errorCallback(Object error, StackTrace stackTrace); | 579 AsyncError errorCallback(Object error, StackTrace stackTrace); |
410 | 580 |
411 /** | 581 /** |
412 * Runs [f] asynchronously in this zone. | 582 * Runs [f] asynchronously in this zone. |
413 */ | 583 */ |
414 void scheduleMicrotask(void f()); | 584 void scheduleMicrotask(void f()); |
415 | 585 |
586 Task createTask(TaskSpecification task, TaskCreate create); | |
587 void runTask(Task task, Object arg1, TaskRun run); | |
588 void cancelTask(Task task, TaskCancel cancel); | |
589 | |
416 /** | 590 /** |
417 * Creates a Timer where the callback is executed in this zone. | 591 * Creates a Timer where the callback is executed in this zone. |
418 */ | 592 */ |
593 @deprecated | |
419 Timer createTimer(Duration duration, void callback()); | 594 Timer createTimer(Duration duration, void callback()); |
420 | 595 |
421 /** | 596 /** |
422 * Creates a periodic Timer where the callback is executed in this zone. | 597 * Creates a periodic Timer where the callback is executed in this zone. |
423 */ | 598 */ |
599 @deprecated | |
424 Timer createPeriodicTimer(Duration period, void callback(Timer timer)); | 600 Timer createPeriodicTimer(Duration period, void callback(Timer timer)); |
425 | 601 |
426 /** | 602 /** |
427 * Prints the given [line]. | 603 * Prints the given [line]. |
428 */ | 604 */ |
429 void print(String line); | 605 void print(String line); |
430 | 606 |
431 /** | 607 /** |
432 * Call to enter the Zone. | 608 * Call to enter the Zone. |
433 * | 609 * |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 error, stackTrace); | 712 error, stackTrace); |
537 } | 713 } |
538 | 714 |
539 void scheduleMicrotask(Zone zone, f()) { | 715 void scheduleMicrotask(Zone zone, f()) { |
540 _ZoneFunction implementation = _delegationTarget._scheduleMicrotask; | 716 _ZoneFunction implementation = _delegationTarget._scheduleMicrotask; |
541 _Zone implZone = implementation.zone; | 717 _Zone implZone = implementation.zone; |
542 ScheduleMicrotaskHandler handler = implementation.function; | 718 ScheduleMicrotaskHandler handler = implementation.function; |
543 handler(implZone, _parentDelegate(implZone), zone, f); | 719 handler(implZone, _parentDelegate(implZone), zone, f); |
544 } | 720 } |
545 | 721 |
546 Timer createTimer(Zone zone, Duration duration, void f()) { | 722 Task createTask(Zone zone, TaskSpecification task, TaskCreate create) { |
547 _ZoneFunction implementation = _delegationTarget._createTimer; | 723 _ZoneFunction implementation = _delegationTarget._createTask; |
548 _Zone implZone = implementation.zone; | 724 _Zone implZone = implementation.zone; |
549 CreateTimerHandler handler = implementation.function; | 725 CreateTaskHandler handler = implementation.function; |
550 return handler(implZone, _parentDelegate(implZone), zone, duration, f); | 726 return handler(implZone, _parentDelegate(implZone), zone, task, create); |
551 } | 727 } |
552 | 728 |
553 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)) { | 729 void runTask(Zone zone, Task task, Object arg, TaskRun run) { |
554 _ZoneFunction implementation = _delegationTarget._createPeriodicTimer; | 730 _ZoneFunction implementation = _delegationTarget._runTask; |
555 _Zone implZone = implementation.zone; | 731 _Zone implZone = implementation.zone; |
556 CreatePeriodicTimerHandler handler = implementation.function; | 732 RunTaskHandler handler = implementation.function; |
557 return handler(implZone, _parentDelegate(implZone), zone, period, f); | 733 handler(implZone, _parentDelegate(implZone), zone, task, arg, run); |
734 } | |
735 | |
736 void cancelTask(Zone zone, Task task, TaskCancel cancel) { | |
737 _ZoneFunction implementation = _delegationTarget._cancelTask; | |
738 _Zone implZone = implementation.zone; | |
739 CancelTaskHandler handler = implementation.function; | |
740 handler(implZone, _parentDelegate(implZone), zone, task, cancel); | |
558 } | 741 } |
559 | 742 |
560 void print(Zone zone, String line) { | 743 void print(Zone zone, String line) { |
561 _ZoneFunction implementation = _delegationTarget._print; | 744 _ZoneFunction implementation = _delegationTarget._print; |
562 _Zone implZone = implementation.zone; | 745 _Zone implZone = implementation.zone; |
563 PrintHandler handler = implementation.function; | 746 PrintHandler handler = implementation.function; |
564 handler(implZone, _parentDelegate(implZone), zone, line); | 747 handler(implZone, _parentDelegate(implZone), zone, line); |
565 } | 748 } |
566 | 749 |
567 Zone fork(Zone zone, ZoneSpecification specification, | 750 Zone fork(Zone zone, ZoneSpecification specification, |
568 Map zoneValues) { | 751 Map zoneValues) { |
569 _ZoneFunction implementation = _delegationTarget._fork; | 752 _ZoneFunction implementation = _delegationTarget._fork; |
570 _Zone implZone = implementation.zone; | 753 _Zone implZone = implementation.zone; |
571 ForkHandler handler = implementation.function; | 754 ForkHandler handler = implementation.function; |
572 return handler( | 755 return handler( |
573 implZone, _parentDelegate(implZone), zone, specification, zoneValues); | 756 implZone, _parentDelegate(implZone), zone, specification, zoneValues); |
574 } | 757 } |
758 | |
759 @deprecated | |
760 Timer createTimer(Zone zone, Duration duration, void f()) { | |
761 _ZoneFunction implementation = _delegationTarget._createTimer; | |
762 _Zone implZone = implementation.zone; | |
763 CreateTimerHandler handler = implementation.function; | |
764 return handler(implZone, _parentDelegate(implZone), zone, duration, f); | |
765 } | |
766 | |
767 @deprecated | |
768 Timer createPeriodicTimer(Zone zone, Duration period, void f(Timer timer)) { | |
769 _ZoneFunction implementation = _delegationTarget._createPeriodicTimer; | |
770 _Zone implZone = implementation.zone; | |
771 CreatePeriodicTimerHandler handler = implementation.function; | |
772 return handler(implZone, _parentDelegate(implZone), zone, period, f); | |
773 } | |
575 } | 774 } |
576 | 775 |
577 | 776 |
578 /** | 777 /** |
579 * Base class for Zone implementations. | 778 * Base class for Zone implementations. |
580 */ | 779 */ |
581 abstract class _Zone implements Zone { | 780 abstract class _Zone implements Zone { |
582 const _Zone(); | 781 const _Zone(); |
583 | 782 |
584 _ZoneFunction get _runUnary; | 783 _ZoneFunction get _runUnary; |
585 _ZoneFunction get _run; | 784 _ZoneFunction get _run; |
586 _ZoneFunction get _runBinary; | 785 _ZoneFunction get _runBinary; |
587 _ZoneFunction get _registerCallback; | 786 _ZoneFunction get _registerCallback; |
588 _ZoneFunction get _registerUnaryCallback; | 787 _ZoneFunction get _registerUnaryCallback; |
589 _ZoneFunction get _registerBinaryCallback; | 788 _ZoneFunction get _registerBinaryCallback; |
590 _ZoneFunction get _errorCallback; | 789 _ZoneFunction get _errorCallback; |
591 _ZoneFunction get _scheduleMicrotask; | 790 _ZoneFunction get _scheduleMicrotask; |
592 _ZoneFunction get _createTimer; | 791 _ZoneFunction get _createTask; |
593 _ZoneFunction get _createPeriodicTimer; | 792 _ZoneFunction get _runTask; |
793 _ZoneFunction get _cancelTask; | |
594 _ZoneFunction get _print; | 794 _ZoneFunction get _print; |
595 _ZoneFunction get _fork; | 795 _ZoneFunction get _fork; |
596 _ZoneFunction get _handleUncaughtError; | 796 _ZoneFunction get _handleUncaughtError; |
797 | |
798 @deprecated | |
799 _ZoneFunction get _createTimer; | |
800 @deprecated | |
801 _ZoneFunction get _createPeriodicTimer; | |
802 | |
597 _Zone get parent; | 803 _Zone get parent; |
598 _ZoneDelegate get _delegate; | 804 _ZoneDelegate get _delegate; |
599 Map get _map; | 805 Map get _map; |
600 | 806 |
601 bool inSameErrorZone(Zone otherZone) { | 807 bool inSameErrorZone(Zone otherZone) { |
602 return identical(this, otherZone) || | 808 return identical(this, otherZone) || |
603 identical(errorZone, otherZone.errorZone); | 809 identical(errorZone, otherZone.errorZone); |
604 } | 810 } |
605 } | 811 } |
606 | 812 |
607 class _CustomZone extends _Zone { | 813 class _CustomZone extends _Zone { |
608 // The actual zone and implementation of each of these | 814 // The actual zone and implementation of each of these |
609 // inheritable zone functions. | 815 // inheritable zone functions. |
610 _ZoneFunction _runUnary; | 816 _ZoneFunction _runUnary; |
611 _ZoneFunction _run; | 817 _ZoneFunction _run; |
612 _ZoneFunction _runBinary; | 818 _ZoneFunction _runBinary; |
613 _ZoneFunction _registerCallback; | 819 _ZoneFunction _registerCallback; |
614 _ZoneFunction _registerUnaryCallback; | 820 _ZoneFunction _registerUnaryCallback; |
615 _ZoneFunction _registerBinaryCallback; | 821 _ZoneFunction _registerBinaryCallback; |
616 _ZoneFunction _errorCallback; | 822 _ZoneFunction _errorCallback; |
617 _ZoneFunction _scheduleMicrotask; | 823 _ZoneFunction _scheduleMicrotask; |
618 _ZoneFunction _createTimer; | 824 _ZoneFunction _createTask; |
619 _ZoneFunction _createPeriodicTimer; | 825 _ZoneFunction _runTask; |
826 _ZoneFunction _cancelTask; | |
620 _ZoneFunction _print; | 827 _ZoneFunction _print; |
621 _ZoneFunction _fork; | 828 _ZoneFunction _fork; |
622 _ZoneFunction _handleUncaughtError; | 829 _ZoneFunction _handleUncaughtError; |
623 | 830 |
831 @deprecated | |
832 _ZoneFunction _createTimer; | |
833 @deprecated | |
834 _ZoneFunction _createPeriodicTimer; | |
835 | |
624 // A cached delegate to this zone. | 836 // A cached delegate to this zone. |
625 ZoneDelegate _delegateCache; | 837 ZoneDelegate _delegateCache; |
626 | 838 |
627 /// The parent zone. | 839 /// The parent zone. |
628 final _Zone parent; | 840 final _Zone parent; |
629 | 841 |
630 /// The zone's scoped value declaration map. | 842 /// The zone's scoped value declaration map. |
631 /// | 843 /// |
632 /// This is always a [HashMap]. | 844 /// This is always a [HashMap]. |
633 final Map _map; | 845 final Map _map; |
(...skipping 25 matching lines...) Expand all Loading... | |
659 : parent._registerUnaryCallback; | 871 : parent._registerUnaryCallback; |
660 _registerBinaryCallback = (specification.registerBinaryCallback != null) | 872 _registerBinaryCallback = (specification.registerBinaryCallback != null) |
661 ? new _ZoneFunction(this, specification.registerBinaryCallback) | 873 ? new _ZoneFunction(this, specification.registerBinaryCallback) |
662 : parent._registerBinaryCallback; | 874 : parent._registerBinaryCallback; |
663 _errorCallback = (specification.errorCallback != null) | 875 _errorCallback = (specification.errorCallback != null) |
664 ? new _ZoneFunction(this, specification.errorCallback) | 876 ? new _ZoneFunction(this, specification.errorCallback) |
665 : parent._errorCallback; | 877 : parent._errorCallback; |
666 _scheduleMicrotask = (specification.scheduleMicrotask != null) | 878 _scheduleMicrotask = (specification.scheduleMicrotask != null) |
667 ? new _ZoneFunction(this, specification.scheduleMicrotask) | 879 ? new _ZoneFunction(this, specification.scheduleMicrotask) |
668 : parent._scheduleMicrotask; | 880 : parent._scheduleMicrotask; |
669 _createTimer = (specification.createTimer != null) | 881 _createTask = (specification.createTask != null) |
670 ? new _ZoneFunction(this, specification.createTimer) | 882 ? new _ZoneFunction(this, specification.createTask) |
671 : parent._createTimer; | 883 : parent._createTask; |
672 _createPeriodicTimer = (specification.createPeriodicTimer != null) | 884 _runTask = (specification.runTask != null) |
673 ? new _ZoneFunction(this, specification.createPeriodicTimer) | 885 ? new _ZoneFunction(this, specification.runTask) |
674 : parent._createPeriodicTimer; | 886 : parent._runTask; |
887 _cancelTask = (specification.cancelTask != null) | |
888 ? new _ZoneFunction(this, specification.runTask) | |
889 : parent._cancelTask; | |
675 _print = (specification.print != null) | 890 _print = (specification.print != null) |
676 ? new _ZoneFunction(this, specification.print) | 891 ? new _ZoneFunction(this, specification.print) |
677 : parent._print; | 892 : parent._print; |
678 _fork = (specification.fork != null) | 893 _fork = (specification.fork != null) |
679 ? new _ZoneFunction(this, specification.fork) | 894 ? new _ZoneFunction(this, specification.fork) |
680 : parent._fork; | 895 : parent._fork; |
681 _handleUncaughtError = (specification.handleUncaughtError != null) | 896 _handleUncaughtError = (specification.handleUncaughtError != null) |
682 ? new _ZoneFunction(this, specification.handleUncaughtError) | 897 ? new _ZoneFunction(this, specification.handleUncaughtError) |
683 : parent._handleUncaughtError; | 898 : parent._handleUncaughtError; |
899 | |
900 // Deprecated fields. | |
901 _createTimer = (specification.createTimer != null) | |
902 ? new _ZoneFunction(this, specification.createTimer) | |
903 : parent._createTimer; | |
904 _createPeriodicTimer = (specification.createPeriodicTimer != null) | |
905 ? new _ZoneFunction(this, specification.createPeriodicTimer) | |
906 : parent._createPeriodicTimer; | |
684 } | 907 } |
685 | 908 |
686 /** | 909 /** |
687 * The closest error-handling zone. | 910 * The closest error-handling zone. |
688 * | 911 * |
689 * Returns `this` if `this` has an error-handler. Otherwise returns the | 912 * Returns `this` if `this` has an error-handler. Otherwise returns the |
690 * parent's error-zone. | 913 * parent's error-zone. |
691 */ | 914 */ |
692 Zone get errorZone => _handleUncaughtError.zone; | 915 Zone get errorZone => _handleUncaughtError.zone; |
693 | 916 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
840 ErrorCallbackHandler handler = implementation.function; | 1063 ErrorCallbackHandler handler = implementation.function; |
841 return handler( | 1064 return handler( |
842 implementationZone, parentDelegate, this, error, stackTrace); | 1065 implementationZone, parentDelegate, this, error, stackTrace); |
843 } | 1066 } |
844 | 1067 |
845 void scheduleMicrotask(void f()) { | 1068 void scheduleMicrotask(void f()) { |
846 _ZoneFunction implementation = this._scheduleMicrotask; | 1069 _ZoneFunction implementation = this._scheduleMicrotask; |
847 assert(implementation != null); | 1070 assert(implementation != null); |
848 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 1071 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
849 ScheduleMicrotaskHandler handler = implementation.function; | 1072 ScheduleMicrotaskHandler handler = implementation.function; |
850 return handler(implementation.zone, parentDelegate, this, f); | 1073 handler(implementation.zone, parentDelegate, this, f); |
851 } | 1074 } |
852 | 1075 |
1076 Task createTask(TaskSpecification task, TaskCreate create) { | |
1077 _ZoneFunction implementation = this._createTask; | |
1078 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | |
1079 CreateTaskHandler handler = implementation.function; | |
1080 return handler(implementation.zone, parentDelegate, this, task, create); | |
1081 } | |
1082 | |
1083 void runTask(Task task, Object arg1, TaskRun run) { | |
1084 _ZoneFunction implementation = this._runTask; | |
1085 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | |
1086 RunTaskHandler handler = implementation.function; | |
1087 handler(implementation.zone, parentDelegate, this, task, arg1, run); | |
1088 } | |
1089 | |
1090 void cancelTask(Task task, TaskCancel cancel) { | |
1091 _ZoneFunction implementation = this._cancelTask; | |
1092 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | |
1093 CancelTaskHandler handler = implementation.function; | |
1094 handler(implementation.zone, parentDelegate, this, task, cancel); | |
1095 } | |
1096 | |
1097 void print(String line) { | |
1098 _ZoneFunction implementation = this._print; | |
1099 assert(implementation != null); | |
1100 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | |
1101 PrintHandler handler = implementation.function; | |
1102 return handler(implementation.zone, parentDelegate, this, line); | |
1103 } | |
1104 | |
1105 @deprecated | |
853 Timer createTimer(Duration duration, void f()) { | 1106 Timer createTimer(Duration duration, void f()) { |
854 _ZoneFunction implementation = this._createTimer; | 1107 _ZoneFunction implementation = this._createTimer; |
855 assert(implementation != null); | 1108 assert(implementation != null); |
856 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 1109 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
857 CreateTimerHandler handler = implementation.function; | 1110 CreateTimerHandler handler = implementation.function; |
858 return handler(implementation.zone, parentDelegate, this, duration, f); | 1111 return handler(implementation.zone, parentDelegate, this, duration, f); |
859 } | 1112 } |
860 | 1113 |
1114 @deprecated | |
861 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) { | 1115 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) { |
862 _ZoneFunction implementation = this._createPeriodicTimer; | 1116 _ZoneFunction implementation = this._createPeriodicTimer; |
863 assert(implementation != null); | 1117 assert(implementation != null); |
864 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | 1118 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); |
865 CreatePeriodicTimerHandler handler = implementation.function; | 1119 CreatePeriodicTimerHandler handler = implementation.function; |
866 return handler( | 1120 return handler( |
867 implementation.zone, parentDelegate, this, duration, f); | 1121 implementation.zone, parentDelegate, this, duration, f); |
868 } | 1122 } |
869 | |
870 void print(String line) { | |
871 _ZoneFunction implementation = this._print; | |
872 assert(implementation != null); | |
873 ZoneDelegate parentDelegate = _parentDelegate(implementation.zone); | |
874 PrintHandler handler = implementation.function; | |
875 return handler(implementation.zone, parentDelegate, this, line); | |
876 } | |
877 } | 1123 } |
878 | 1124 |
879 void _rootHandleUncaughtError( | 1125 void _rootHandleUncaughtError( |
880 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace) { | 1126 Zone self, ZoneDelegate parent, Zone zone, error, StackTrace stackTrace) { |
881 _schedulePriorityAsyncCallback(() { | 1127 _schedulePriorityAsyncCallback(() { |
882 if (error == null) error = new NullThrownError(); | 1128 if (error == null) error = new NullThrownError(); |
883 if (stackTrace == null) throw error; | 1129 if (stackTrace == null) throw error; |
884 _rethrow(error, stackTrace); | 1130 _rethrow(error, stackTrace); |
885 }); | 1131 }); |
886 } | 1132 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
942 void _rootScheduleMicrotask(Zone self, ZoneDelegate parent, Zone zone, f()) { | 1188 void _rootScheduleMicrotask(Zone self, ZoneDelegate parent, Zone zone, f()) { |
943 if (!identical(_ROOT_ZONE, zone)) { | 1189 if (!identical(_ROOT_ZONE, zone)) { |
944 bool hasErrorHandler = !_ROOT_ZONE.inSameErrorZone(zone); | 1190 bool hasErrorHandler = !_ROOT_ZONE.inSameErrorZone(zone); |
945 f = zone.bindCallback(f, runGuarded: hasErrorHandler); | 1191 f = zone.bindCallback(f, runGuarded: hasErrorHandler); |
946 // Use root zone as event zone if the function is already bound. | 1192 // Use root zone as event zone if the function is already bound. |
947 zone = _ROOT_ZONE; | 1193 zone = _ROOT_ZONE; |
948 } | 1194 } |
949 _scheduleAsyncCallback(f); | 1195 _scheduleAsyncCallback(f); |
950 } | 1196 } |
951 | 1197 |
1198 Task _rootcreateTask(Zone self, ZoneDelegate parent, Zone zone, | |
1199 TaskSpecification taskSpecification, TaskCreate create) { | |
1200 return create(taskSpecification, zone); | |
1201 } | |
1202 | |
1203 void _rootRunTask(Zone self, ZoneDelegate parent, Zone zone, Task task, | |
1204 Object arg, TaskRun run) { | |
1205 if (Zone._current == zone) run(task, arg, zone); | |
1206 | |
1207 Zone old = Zone._enter(zone); | |
1208 try { | |
1209 run(task, arg, zone); | |
1210 } finally { | |
1211 Zone._leave(old); | |
1212 } | |
1213 } | |
1214 | |
1215 void _rootCancelTask(Zone self, ZoneDelegate parent, Zone zone, Task task, | |
1216 TaskCancel cancel) { | |
1217 cancel(task, zone); | |
1218 } | |
1219 | |
952 Timer _rootCreateTimer(Zone self, ZoneDelegate parent, Zone zone, | 1220 Timer _rootCreateTimer(Zone self, ZoneDelegate parent, Zone zone, |
953 Duration duration, void callback()) { | 1221 Duration duration, void callback()) { |
954 if (!identical(_ROOT_ZONE, zone)) { | 1222 if (!identical(_ROOT_ZONE, zone)) { |
955 callback = zone.bindCallback(callback); | 1223 callback = zone.bindCallback(callback); |
956 } | 1224 } |
957 return Timer._createTimer(duration, callback); | 1225 return Timer._createTimer(duration, callback); |
958 } | 1226 } |
959 | 1227 |
960 Timer _rootCreatePeriodicTimer( | 1228 Timer _rootCreatePeriodicTimer( |
961 Zone self, ZoneDelegate parent, Zone zone, | 1229 Zone self, ZoneDelegate parent, Zone zone, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1013 _ZoneFunction get _registerCallback => | 1281 _ZoneFunction get _registerCallback => |
1014 const _ZoneFunction(_ROOT_ZONE, _rootRegisterCallback); | 1282 const _ZoneFunction(_ROOT_ZONE, _rootRegisterCallback); |
1015 _ZoneFunction get _registerUnaryCallback => | 1283 _ZoneFunction get _registerUnaryCallback => |
1016 const _ZoneFunction(_ROOT_ZONE, _rootRegisterUnaryCallback); | 1284 const _ZoneFunction(_ROOT_ZONE, _rootRegisterUnaryCallback); |
1017 _ZoneFunction get _registerBinaryCallback => | 1285 _ZoneFunction get _registerBinaryCallback => |
1018 const _ZoneFunction(_ROOT_ZONE, _rootRegisterBinaryCallback); | 1286 const _ZoneFunction(_ROOT_ZONE, _rootRegisterBinaryCallback); |
1019 _ZoneFunction get _errorCallback => | 1287 _ZoneFunction get _errorCallback => |
1020 const _ZoneFunction(_ROOT_ZONE, _rootErrorCallback); | 1288 const _ZoneFunction(_ROOT_ZONE, _rootErrorCallback); |
1021 _ZoneFunction get _scheduleMicrotask => | 1289 _ZoneFunction get _scheduleMicrotask => |
1022 const _ZoneFunction(_ROOT_ZONE, _rootScheduleMicrotask); | 1290 const _ZoneFunction(_ROOT_ZONE, _rootScheduleMicrotask); |
1023 _ZoneFunction get _createTimer => | 1291 _ZoneFunction get _createTask => |
1024 const _ZoneFunction(_ROOT_ZONE, _rootCreateTimer); | 1292 const _ZoneFunction(_ROOT_ZONE, _rootcreateTask); |
1025 _ZoneFunction get _createPeriodicTimer => | 1293 _ZoneFunction get _runTask => |
1026 const _ZoneFunction(_ROOT_ZONE, _rootCreatePeriodicTimer); | 1294 const _ZoneFunction(_ROOT_ZONE, _rootRunTask); |
1295 _ZoneFunction get _cancelTask => | |
1296 const _ZoneFunction(_ROOT_ZONE, _rootCancelTask); | |
1027 _ZoneFunction get _print => | 1297 _ZoneFunction get _print => |
1028 const _ZoneFunction(_ROOT_ZONE, _rootPrint); | 1298 const _ZoneFunction(_ROOT_ZONE, _rootPrint); |
1029 _ZoneFunction get _fork => | 1299 _ZoneFunction get _fork => |
1030 const _ZoneFunction(_ROOT_ZONE, _rootFork); | 1300 const _ZoneFunction(_ROOT_ZONE, _rootFork); |
1031 _ZoneFunction get _handleUncaughtError => | 1301 _ZoneFunction get _handleUncaughtError => |
1032 const _ZoneFunction(_ROOT_ZONE, _rootHandleUncaughtError); | 1302 const _ZoneFunction(_ROOT_ZONE, _rootHandleUncaughtError); |
1033 | 1303 |
1304 @deprecated | |
1305 _ZoneFunction get _createTimer => | |
1306 const _ZoneFunction(_ROOT_ZONE, _rootCreateTimer); | |
1307 @deprecated | |
1308 _ZoneFunction get _createPeriodicTimer => | |
1309 const _ZoneFunction(_ROOT_ZONE, _rootCreatePeriodicTimer); | |
1310 | |
1034 // The parent zone. | 1311 // The parent zone. |
1035 _Zone get parent => null; | 1312 _Zone get parent => null; |
1036 | 1313 |
1037 /// The zone's scoped value declaration map. | 1314 /// The zone's scoped value declaration map. |
1038 /// | 1315 /// |
1039 /// This is always a [HashMap]. | 1316 /// This is always a [HashMap]. |
1040 Map get _map => _rootMap; | 1317 Map get _map => _rootMap; |
1041 | 1318 |
1042 static Map _rootMap = new HashMap(); | 1319 static Map _rootMap = new HashMap(); |
1043 | 1320 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1148 ZoneUnaryCallback registerUnaryCallback(f(arg)) => f; | 1425 ZoneUnaryCallback registerUnaryCallback(f(arg)) => f; |
1149 | 1426 |
1150 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) => f; | 1427 ZoneBinaryCallback registerBinaryCallback(f(arg1, arg2)) => f; |
1151 | 1428 |
1152 AsyncError errorCallback(Object error, StackTrace stackTrace) => null; | 1429 AsyncError errorCallback(Object error, StackTrace stackTrace) => null; |
1153 | 1430 |
1154 void scheduleMicrotask(void f()) { | 1431 void scheduleMicrotask(void f()) { |
1155 _rootScheduleMicrotask(null, null, this, f); | 1432 _rootScheduleMicrotask(null, null, this, f); |
1156 } | 1433 } |
1157 | 1434 |
1435 Task createTask(TaskSpecification task, TaskCreate create) { | |
1436 return _rootcreateTask(null, null, this, task, create); | |
1437 } | |
1438 | |
1439 void runTask(Task task, Object arg, TaskRun run) { | |
1440 _rootRunTask(null, null, this, task, arg, run); | |
1441 } | |
1442 | |
1443 void cancelTask(Task task, TaskCancel cancel) { | |
1444 _rootCancelTask(null, null, this, task, cancel); | |
1445 } | |
1446 | |
1158 Timer createTimer(Duration duration, void f()) { | 1447 Timer createTimer(Duration duration, void f()) { |
1159 return Timer._createTimer(duration, f); | 1448 return Timer._createTimer(duration, f); |
1160 } | 1449 } |
1161 | 1450 |
1162 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) { | 1451 Timer createPeriodicTimer(Duration duration, void f(Timer timer)) { |
1163 return Timer._createPeriodicTimer(duration, f); | 1452 return Timer._createPeriodicTimer(duration, f); |
1164 } | 1453 } |
1165 | 1454 |
1166 void print(String line) { | 1455 void print(String line) { |
1167 printToConsole(line); | 1456 printToConsole(line); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1226 handleUncaughtError: errorHandler); | 1515 handleUncaughtError: errorHandler); |
1227 } | 1516 } |
1228 Zone zone = Zone.current.fork(specification: zoneSpecification, | 1517 Zone zone = Zone.current.fork(specification: zoneSpecification, |
1229 zoneValues: zoneValues); | 1518 zoneValues: zoneValues); |
1230 if (onError != null) { | 1519 if (onError != null) { |
1231 return zone.runGuarded(body); | 1520 return zone.runGuarded(body); |
1232 } else { | 1521 } else { |
1233 return zone.run(body); | 1522 return zone.run(body); |
1234 } | 1523 } |
1235 } | 1524 } |
OLD | NEW |