Chromium Code Reviews| 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 // runGuarded calls run, captures the synchronous error (if any) and | |
| 14 // gives that one to handleUncaughtError. | |
|
Lasse Reichstein Nielsen
2013/09/23 14:24:12
Comment seems unrelated to test.
floitsch
2013/09/23 17:12:07
Done.
| |
| 15 | |
| 16 Expect.identical(Zone.ROOT, Zone.current); | |
| 17 Zone forked; | |
| 18 forked = Zone.current.fork(null, new ZoneDescription( | |
| 19 createPeriodicTimer: (Zone self, ZoneDelegate parent, Zone origin, | |
| 20 Duration period, f(Timer timer)) { | |
|
Lasse Reichstein Nielsen
2013/09/23 14:24:12
Indent to after '('.
floitsch
2013/09/23 17:12:07
Done.
| |
| 21 events.add("forked.createPeriodicTimer"); | |
| 22 return parent.createPeriodicTimer(origin, period, (Timer timer) { | |
| 23 events.add("wrapped function ${period.inMilliseconds}"); | |
| 24 f(timer); | |
| 25 }); | |
| 26 })); | |
| 27 | |
| 28 asyncStart(); | |
| 29 int tickCount = 0; | |
| 30 forked.run(() { | |
| 31 new Timer.periodic(const Duration(milliseconds: 5), | |
| 32 (Timer timer) { | |
| 33 events.add("periodic Timer $tickCount"); | |
| 34 Expect.identical(forked, Zone.current); | |
| 35 tickCount++; | |
| 36 if (tickCount == 4) { | |
| 37 timer.cancel(); | |
| 38 // Allow some time in case the cancel didn't work. | |
| 39 new Timer(const Duration(milliseconds: 20), done.complete); | |
| 40 } | |
| 41 }); | |
| 42 }); | |
| 43 | |
| 44 Expect.identical(Zone.ROOT, Zone.current); | |
| 45 events.add("after createPeriodicTimer"); | |
| 46 | |
| 47 done.future.whenComplete(() { | |
| 48 Expect.listEquals( | |
| 49 [ "forked.createPeriodicTimer", "after createPeriodicTimer", | |
| 50 "wrapped function 5", "periodic Timer 0", | |
| 51 "wrapped function 5", "periodic Timer 1", | |
| 52 "wrapped function 5", "periodic Timer 2", | |
| 53 "wrapped function 5", "periodic Timer 3" ], | |
| 54 events); | |
| 55 asyncEnd(); | |
| 56 }); | |
| 57 } | |
| OLD | NEW |