| 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 'dart:async'; |
| 7 import 'dart:isolate'; |
| 8 |
| 9 class A { |
| 10 add(x) => print(x); |
| 11 } |
| 12 var events = []; |
| 13 |
| 14 body() { |
| 15 events.add("body entry"); |
| 16 runAsync(() { |
| 17 events.add("run async body"); |
| 18 throw "foo"; |
| 19 }); |
| 20 return 499; |
| 21 } |
| 22 |
| 23 onAsyncHandler(fun) { |
| 24 events.add("async handler"); |
| 25 runAsync(fun); |
| 26 events.add("async handler done"); |
| 27 } |
| 28 |
| 29 onErrorHandler(e) { |
| 30 events.add("error: $e"); |
| 31 } |
| 32 |
| 33 onDoneHandler() { |
| 34 events.add("done"); |
| 35 } |
| 36 |
| 37 main() { |
| 38 // We keep a ReceivePort open until all tests are done. This way the VM will |
| 39 // hang if the callbacks are not invoked and the test will time out. |
| 40 var port = new ReceivePort(); |
| 41 |
| 42 // Test that runZonedExperimental works when async, error and done are used. |
| 43 var result = runZonedExperimental( |
| 44 body, |
| 45 onRunAsync: onAsyncHandler, |
| 46 onError: onErrorHandler, |
| 47 onDone: onDoneHandler); |
| 48 events.add("after"); |
| 49 Timer.run(() { |
| 50 Expect.listEquals( |
| 51 ["body entry", |
| 52 "async handler", "async handler done", |
| 53 "after", |
| 54 "run async body", |
| 55 "error: foo", |
| 56 "done"], |
| 57 events); |
| 58 port.close(); |
| 59 }); |
| 60 } |
| OLD | NEW |