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 'package:async_helper/async_helper.dart'; |
| 8 import 'catch_errors.dart'; |
| 9 |
| 10 main() { |
| 11 asyncStart(); |
| 12 Completer done = new Completer(); |
| 13 |
| 14 // Make sure that the zones use the scheduleMicrotask of their zones. |
| 15 int scheduleMicrotaskCount = 0; |
| 16 Completer completer; |
| 17 Completer completer2; |
| 18 Future future; |
| 19 Future future2; |
| 20 runZonedScheduleMicrotask(() { |
| 21 completer = new Completer(); |
| 22 completer.complete(499); |
| 23 completer2 = new Completer.sync(); |
| 24 completer2.complete(-499); |
| 25 future = new Future.value(42); |
| 26 future2 = new Future.error(11); |
| 27 }, onScheduleMicrotask: (f) { |
| 28 scheduleMicrotaskCount++; |
| 29 scheduleMicrotask(f); |
| 30 }); |
| 31 int openCallbackCount = 0; |
| 32 |
| 33 openCallbackCount++; |
| 34 completer.future.then((x) { |
| 35 Expect.equals(499, x); |
| 36 openCallbackCount--; |
| 37 if (openCallbackCount == 0) done.complete(); |
| 38 }); |
| 39 |
| 40 openCallbackCount++; |
| 41 completer2.future.then((x) { |
| 42 Expect.equals(-499, x); |
| 43 openCallbackCount--; |
| 44 if (openCallbackCount == 0) done.complete(); |
| 45 }); |
| 46 |
| 47 openCallbackCount++; |
| 48 future.then((x) { |
| 49 Expect.equals(42, x); |
| 50 openCallbackCount--; |
| 51 if (openCallbackCount == 0) done.complete(); |
| 52 }); |
| 53 |
| 54 openCallbackCount++; |
| 55 future2.catchError((x) { |
| 56 Expect.equals(11, x); |
| 57 openCallbackCount--; |
| 58 if (openCallbackCount == 0) done.complete(); |
| 59 }); |
| 60 |
| 61 done.future.whenComplete(() { |
| 62 Expect.equals(4, scheduleMicrotaskCount); |
| 63 asyncEnd(); |
| 64 }); |
| 65 } |
OLD | NEW |