OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'package:expect/expect.dart'; |
| 6 import 'package:async_helper/async_helper.dart'; |
| 7 import 'dart:async'; |
| 8 |
| 9 main() { |
| 10 Completer done = new Completer(); |
| 11 List events = []; |
| 12 |
| 13 Expect.identical(Zone.ROOT, Zone.current); |
| 14 Zone forked; |
| 15 forked = Zone.current.fork(specification: new ZoneSpecification( |
| 16 fork: (Zone self, ZoneDelegate parent, Zone origin, |
| 17 ZoneSpecification zoneSpecification, Map mapValues) { |
| 18 // The zone is still the same as when origin.run was invoked, which |
| 19 // is the root zone. (The origin zone hasn't been set yet). |
| 20 Expect.identical(Zone.ROOT, Zone.current); |
| 21 events.add("forked.fork"); |
| 22 Function descriptionRun = zoneSpecification.run; |
| 23 ZoneSpecification modified = new ZoneSpecification.from( |
| 24 zoneSpecification, |
| 25 run: (self, parent, origin, f) { |
| 26 events.add("wrapped run"); |
| 27 return descriptionRun(self, parent, origin, () { |
| 28 events.add("wrapped f"); |
| 29 return f(); |
| 30 }); |
| 31 }); |
| 32 return parent.fork(origin, modified, mapValues); |
| 33 })); |
| 34 |
| 35 events.add("start"); |
| 36 Zone forkedChild = forked.fork(specification: new ZoneSpecification( |
| 37 run: (Zone self, ZoneDelegate parent, Zone origin, f()) { |
| 38 events.add("executing child run"); |
| 39 return parent.run(origin, f); |
| 40 })); |
| 41 |
| 42 events.add("after child fork"); |
| 43 Expect.identical(Zone.ROOT, Zone.current); |
| 44 |
| 45 forkedChild.run(() { |
| 46 events.add("child run"); |
| 47 }); |
| 48 |
| 49 events.add("after child run"); |
| 50 |
| 51 Expect.listEquals( |
| 52 [ "start", |
| 53 "forked.fork", |
| 54 "after child fork", |
| 55 "wrapped run", "executing child run", "wrapped f", "child run", |
| 56 "after child run" ], |
| 57 events); |
| 58 } |
OLD | NEW |