Use a synchronous completer in _futurize. (flutter/engine#4379)

This keeps the futures chain shorter.
This commit is contained in:
amirh
2017-11-21 15:31:04 -08:00
committed by GitHub
parent 2db5ec9775
commit 353f9063f4

View File

@@ -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;
}