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 createTimer: (Zone self, ZoneDelegate parent, Zone origin, |
| 17 Duration duration, f()) { |
| 18 events.add("forked.createTimer"); |
| 19 return parent.createTimer(origin, duration, () { |
| 20 events.add("wrapped function ${duration.inMilliseconds}"); |
| 21 f(); |
| 22 }); |
| 23 })); |
| 24 |
| 25 asyncStart(); |
| 26 forked.run(() { |
| 27 Timer timer = new Timer(const Duration(milliseconds: 20), () { |
| 28 events.add("createTimer"); |
| 29 Expect.identical(forked, Zone.current); |
| 30 done.complete(true); |
| 31 }); |
| 32 }); |
| 33 |
| 34 Expect.identical(Zone.ROOT, Zone.current); |
| 35 events.add("after createTimer"); |
| 36 |
| 37 done.future.whenComplete(() { |
| 38 Expect.listEquals( |
| 39 [ "forked.createTimer", "after createTimer", "wrapped function 20", |
| 40 "createTimer" ], |
| 41 events); |
| 42 asyncEnd(); |
| 43 }); |
| 44 } |
OLD | NEW |