| 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:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import 'package:async_helper/async_helper.dart'; | 7 import 'package:async_helper/async_helper.dart'; |
| 8 | 8 |
| 9 main() { | 9 main() { |
| 10 asyncStart(); | 10 asyncStart(); |
| 11 Completer done = new Completer(); | 11 Completer done = new Completer(); |
| 12 | 12 |
| 13 // Make sure that the zones use the runAsync of their zones. | 13 // Make sure that the zones use the scheduleMicrotask of their zones. |
| 14 int runAsyncCount = 0; | 14 int scheduleMicrotaskCount = 0; |
| 15 Completer completer; | 15 Completer completer; |
| 16 Completer completer2; | 16 Completer completer2; |
| 17 Future future; | 17 Future future; |
| 18 Future future2; | 18 Future future2; |
| 19 runZonedExperimental(() { | 19 runZonedExperimental(() { |
| 20 completer = new Completer(); | 20 completer = new Completer(); |
| 21 completer.complete(499); | 21 completer.complete(499); |
| 22 completer2 = new Completer.sync(); | 22 completer2 = new Completer.sync(); |
| 23 completer2.complete(-499); | 23 completer2.complete(-499); |
| 24 future = new Future.value(42); | 24 future = new Future.value(42); |
| 25 future2 = new Future.error(11); | 25 future2 = new Future.error(11); |
| 26 }, onRunAsync: (f) { | 26 }, onScheduleMicrotask: (f) { |
| 27 runAsyncCount++; | 27 scheduleMicrotaskCount++; |
| 28 runAsync(f); | 28 scheduleMicrotask(f); |
| 29 }); | 29 }); |
| 30 int openCallbackCount = 0; | 30 int openCallbackCount = 0; |
| 31 | 31 |
| 32 openCallbackCount++; | 32 openCallbackCount++; |
| 33 completer.future.then((x) { | 33 completer.future.then((x) { |
| 34 Expect.equals(499, x); | 34 Expect.equals(499, x); |
| 35 openCallbackCount--; | 35 openCallbackCount--; |
| 36 if (openCallbackCount == 0) done.complete(); | 36 if (openCallbackCount == 0) done.complete(); |
| 37 }); | 37 }); |
| 38 | 38 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 51 }); | 51 }); |
| 52 | 52 |
| 53 openCallbackCount++; | 53 openCallbackCount++; |
| 54 future2.catchError((x) { | 54 future2.catchError((x) { |
| 55 Expect.equals(11, x); | 55 Expect.equals(11, x); |
| 56 openCallbackCount--; | 56 openCallbackCount--; |
| 57 if (openCallbackCount == 0) done.complete(); | 57 if (openCallbackCount == 0) done.complete(); |
| 58 }); | 58 }); |
| 59 | 59 |
| 60 done.future.whenComplete(() { | 60 done.future.whenComplete(() { |
| 61 Expect.equals(4, runAsyncCount); | 61 Expect.equals(4, scheduleMicrotaskCount); |
| 62 asyncEnd(); | 62 asyncEnd(); |
| 63 }); | 63 }); |
| 64 } | 64 } |
| OLD | NEW |