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