未验证 提交 b6aee825 编写于 作者: A amirh 提交者: GitHub

Use a synchronous completer in _futurize. (#4379)

This keeps the futures chain shorter.
上级 5f9c8522
......@@ -2480,16 +2480,19 @@ typedef String _Callbacker<T>(_Callback<T> callback);
/// }
/// ```
///
Future<T> _futurize<T>(_Callbacker<T> callbacker) async {
Completer<T> completer = new Completer<T>();
String err = callbacker(completer.complete);
if (err != null) {
Future<T> _futurize<T>(_Callbacker<T> callbacker) {
final Completer<T> completer = new Completer<T>.sync();
final String err = callbacker((t) {
if (t == null) {
completer.completeError(new Exception('operation failed'));
} else {
completer.complete(t);
}
});
if (err != null)
throw new Exception(err);
}
T result = await completer.future;
if (result == null) {
throw new Exception('operation failed');
}
return result;
return completer.future;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册