mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:27:17 +00:00
70f6e6553c
It seems that there's some fiddliness when writing error handling lambdas in strong mode. async_await_sync_completer_test: The lambda was implicitly trying to return the result of a throw, which was Never. I've switched it to this syntax, which implicitly returns Null instead. stream_iterator_test: The error handler needs to return a Bool, for compatibility with the Future. I'm open to suggestions for cleaner fixes to these bugs. Change-Id: Ifc646a965d4b435512277da96ffb5e0b429114cb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/141164 Commit-Queue: Liam Appelbe <liama@google.com> Reviewed-by: Régis Crelier <regis@google.com> Reviewed-by: Alexander Markov <alexmarkov@google.com>
59 lines
1.8 KiB
Dart
59 lines
1.8 KiB
Dart
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'dart:async';
|
|
import 'package:expect/expect.dart';
|
|
import 'package:async_helper/async_helper.dart';
|
|
|
|
import 'dart:async';
|
|
|
|
var events = [];
|
|
var delayedValue = new Completer();
|
|
var delayedError = new Completer();
|
|
|
|
foo() async {
|
|
// Because of this `await null` the function returns and lets the caller
|
|
// install handlers. When the function finishes, it can then synchronously
|
|
// propagate the values.
|
|
await null;
|
|
new Future.microtask(() => 'in microtask')
|
|
.then(events.add)
|
|
.then(delayedValue.complete);
|
|
return 'in async function';
|
|
}
|
|
|
|
bar() async {
|
|
// Because of this `await null` the function returns and lets the caller
|
|
// install handlers. When the function finishes, it can then synchronously
|
|
// propagate the values.
|
|
await null;
|
|
new Future<void>.microtask(() => throw 'in microtask error')
|
|
.catchError(events.add)
|
|
.then(delayedError.complete);
|
|
throw 'in async function error';
|
|
}
|
|
|
|
void main() {
|
|
asyncStart();
|
|
var asyncValueFuture = foo().then(events.add);
|
|
var asyncErrorFuture = bar().catchError(events.add);
|
|
Future.wait(<Future>[
|
|
asyncValueFuture,
|
|
delayedValue.future,
|
|
asyncErrorFuture,
|
|
delayedError.future
|
|
]).then((_) {
|
|
// The body completed before nested microtask. So they should appear
|
|
// before the delayed functions. In other words, the async function should
|
|
// not unnecessarily delay the propagation of errors and values.
|
|
Expect.listEquals([
|
|
"in async function",
|
|
"in async function error",
|
|
"in microtask",
|
|
"in microtask error"
|
|
], events);
|
|
asyncEnd();
|
|
});
|
|
}
|