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 class A { | 10 class A { |
11 add(x) => print(x); | 11 add(x) => print(x); |
12 } | 12 } |
| 13 |
13 var events = []; | 14 var events = []; |
14 | 15 |
15 body() { | 16 body() { |
16 events.add("body entry"); | 17 events.add("body entry"); |
17 scheduleMicrotask(() { | 18 scheduleMicrotask(() { |
18 events.add("run async body"); | 19 events.add("run async body"); |
19 throw "foo"; | 20 throw "foo"; |
20 }); | 21 }); |
21 return 499; | 22 return 499; |
22 } | 23 } |
23 | 24 |
24 onAsyncHandler(fun) { | 25 onAsyncHandler(fun) { |
25 events.add("async handler"); | 26 events.add("async handler"); |
26 scheduleMicrotask(fun); | 27 scheduleMicrotask(fun); |
27 events.add("async handler done"); | 28 events.add("async handler done"); |
28 } | 29 } |
29 | 30 |
30 onErrorHandler(e) { | 31 onErrorHandler(e) { |
31 events.add("error: $e"); | 32 events.add("error: $e"); |
32 } | 33 } |
33 | 34 |
34 main() { | 35 main() { |
35 asyncStart(); | 36 asyncStart(); |
36 | 37 |
37 // Test that runZonedScheduleMicrotask works when async, error and done | 38 // Test that runZonedScheduleMicrotask works when async, error and done |
38 // are used. | 39 // are used. |
39 var result = runZonedScheduleMicrotask( | 40 var result = runZonedScheduleMicrotask(body, |
40 body, | 41 onScheduleMicrotask: onAsyncHandler, onError: onErrorHandler); |
41 onScheduleMicrotask: onAsyncHandler, | |
42 onError: onErrorHandler); | |
43 events.add("after"); | 42 events.add("after"); |
44 Timer.run(() { | 43 Timer.run(() { |
45 Expect.listEquals( | 44 Expect.listEquals([ |
46 ["body entry", | 45 "body entry", |
47 "async handler", "async handler done", | 46 "async handler", |
48 "after", | 47 "async handler done", |
49 "run async body", | 48 "after", |
50 "error: foo"], | 49 "run async body", |
51 events); | 50 "error: foo" |
| 51 ], events); |
52 asyncEnd(); | 52 asyncEnd(); |
53 }); | 53 }); |
54 } | 54 } |
OLD | NEW |