OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, 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 'dart:async'; |
| 6 import 'package:expect/expect.dart'; |
| 7 import 'package:async_helper/async_helper.dart'; |
| 8 |
| 9 import 'dart:async'; |
| 10 |
| 11 var events = []; |
| 12 var delayedValue = new Completer(); |
| 13 var delayedError = new Completer(); |
| 14 |
| 15 foo() async { |
| 16 new Future.microtask(() => 'in microtask') |
| 17 .then(events.add) |
| 18 .then(delayedValue.complete); |
| 19 return 'in async function'; |
| 20 } |
| 21 |
| 22 bar() async { |
| 23 new Future.microtask(() => throw 'in microtask error') |
| 24 .catchError(events.add) |
| 25 .then(delayedError.complete); |
| 26 throw 'in async function error'; |
| 27 } |
| 28 |
| 29 void main() { |
| 30 asyncStart(); |
| 31 var asyncValueFuture = foo().then(events.add); |
| 32 var asyncErrorFuture = bar().catchError(events.add); |
| 33 Future.wait([ |
| 34 asyncValueFuture, |
| 35 delayedValue.future, |
| 36 asyncErrorFuture, |
| 37 delayedError.future]).then((_) { |
| 38 // The body completed before nested microtask. So they should appear |
| 39 // before the delayed functions. In other words, the async function should |
| 40 // not unnecessarily delay the propagation of errors and values. |
| 41 Expect.listEquals([ |
| 42 "in async function", |
| 43 "in async function error", |
| 44 "in microtask", |
| 45 "in microtask error"], |
| 46 events); |
| 47 asyncEnd(); |
| 48 }); |
| 49 } |
OLD | NEW |