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