| 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:async_helper/async_helper.dart'; | 5 import 'package:async_helper/async_helper.dart'; |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'catch_errors.dart'; | 8 import 'catch_errors.dart'; |
| 9 | 9 |
| 10 main() { | 10 main() { |
| 11 asyncStart(); | 11 asyncStart(); |
| 12 Completer done = new Completer(); |
| 13 |
| 12 var events = []; | 14 var events = []; |
| 13 // Tests that errors that have been delayed by several milliseconds with | 15 // Tests that errors that have been delayed by several milliseconds with |
| 14 // Timers are still caught by `catchErrors`. | 16 // Timers are still caught by `catchErrors`. |
| 15 catchErrors(() { | 17 catchErrors(() { |
| 16 events.add("catch error entry"); | 18 events.add("catch error entry"); |
| 17 Timer.run(() { throw "timer error"; }); | 19 Timer.run(() { throw "timer error"; }); |
| 18 new Timer(const Duration(milliseconds: 100), () { throw "timer2 error"; }); | 20 new Timer(const Duration(milliseconds: 100), () { throw "timer2 error"; }); |
| 19 new Future.value(499).then((x) { | 21 new Future.value(499).then((x) { |
| 20 new Timer(const Duration(milliseconds: 200), () { throw x; }); | 22 new Timer(const Duration(milliseconds: 200), () { |
| 23 done.complete(499); |
| 24 throw x; |
| 25 }); |
| 21 }); | 26 }); |
| 22 throw "catch error"; | 27 throw "catch error"; |
| 23 }).listen((x) { | 28 }).listen((x) { |
| 24 events.add(x); | 29 events.add(x); |
| 25 }, | 30 }, |
| 26 onDone: () { | 31 onDone: () { Expect.fail("Unexpected callback"); }); |
| 32 done.future.whenComplete(() { |
| 33 // Give time to execute the callbacks. |
| 34 Timer.run(() { |
| 27 Expect.listEquals([ | 35 Expect.listEquals([ |
| 28 "catch error entry", | 36 "catch error entry", |
| 29 "main exit", | 37 "main exit", |
| 30 "catch error", | 38 "catch error", |
| 31 "timer error", | 39 "timer error", |
| 32 "timer2 error", | 40 "timer2 error", |
| 33 499, | 41 499, |
| 34 ], | 42 ], |
| 35 events); | 43 events); |
| 36 asyncEnd(); | 44 asyncEnd(); |
| 37 }); | 45 }); |
| 46 }); |
| 38 events.add("main exit"); | 47 events.add("main exit"); |
| 39 } | 48 } |
| OLD | NEW |