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 import 'package:expect/expect.dart'; | 5 import 'package:expect/expect.dart'; |
6 import 'package:async_helper/async_helper.dart'; | 6 import 'package:async_helper/async_helper.dart'; |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 main() { | 9 main() { |
10 Completer done = new Completer(); | 10 Completer done = new Completer(); |
11 List events = []; | 11 List events = []; |
12 | 12 |
13 bool shouldForward = true; | 13 bool shouldForward = true; |
14 Expect.identical(Zone.ROOT, Zone.current); | 14 Expect.identical(Zone.ROOT, Zone.current); |
15 Zone forked = Zone.current.fork(specification: new ZoneSpecification( | 15 Zone forked = Zone.current.fork(specification: new ZoneSpecification(runUnary: |
16 runUnary: (Zone self, ZoneDelegate parent, Zone origin, f(arg), arg) { | 16 <R, T>(Zone self, ZoneDelegate parent, Zone origin, R f(arg), T arg) { |
17 // The zone is still the same as when origin.run was invoked, which | 17 // The zone is still the same as when origin.run was invoked, which |
18 // is the root zone. (The origin zone hasn't been set yet). | 18 // is the root zone. (The origin zone hasn't been set yet). |
19 Expect.identical(Zone.current, Zone.ROOT); | 19 Expect.identical(Zone.current, Zone.ROOT); |
20 events.add("forked.run1"); | 20 events.add("forked.run1"); |
21 if (shouldForward) return parent.runUnary(origin, f, arg + 1); | 21 if (shouldForward) { |
22 return 42; | 22 var nextArg = (arg as int) + 1; |
| 23 return parent.runUnary(origin, f, nextArg as T); |
| 24 } |
| 25 return 42 as R; |
23 })); | 26 })); |
24 | 27 |
25 events.add("zone forked"); | 28 events.add("zone forked"); |
26 Zone expectedZone = forked; | 29 Zone expectedZone = forked; |
27 var result = forked.runUnary((arg) { | 30 var result = forked.runUnary((arg) { |
28 Expect.identical(expectedZone, Zone.current); | 31 Expect.identical(expectedZone, Zone.current); |
29 events.add("run closure"); | 32 events.add("run closure"); |
30 return arg + 3; | 33 return arg + 3; |
31 }, 495); | 34 }, 495); |
32 Expect.equals(499, result); | 35 Expect.equals(499, result); |
(...skipping 30 matching lines...) Expand all Loading... |
63 "forked.run1", | 66 "forked.run1", |
64 "executed run2", | 67 "executed run2", |
65 "forked.run1", | 68 "forked.run1", |
66 "run closure 2", | 69 "run closure 2", |
67 "after nested scheduleMicrotask", | 70 "after nested scheduleMicrotask", |
68 "run closure 3" | 71 "run closure 3" |
69 ], events); | 72 ], events); |
70 asyncEnd(); | 73 asyncEnd(); |
71 }); | 74 }); |
72 } | 75 } |
OLD | NEW |