Delinting future awaits round 3 (#10791)

* round 3

* partially address comments

* merge

* review notes

* review

* review

* review
This commit is contained in:
xster 2017-09-20 17:24:43 -07:00 committed by GitHub
parent 8475e0b290
commit e28765a997
10 changed files with 45 additions and 24 deletions

View File

@ -42,7 +42,7 @@ const List<String> _kRequiredOptions = const <String>[
Future<Null> main(List<String> args) async {
final AppContext executableContext = new AppContext();
executableContext.setVariable(Logger, new StdoutLogger());
executableContext.runInZone(() {
await executableContext.runInZone(() {
// Initialize the context with some defaults.
context.putIfAbsent(Platform, () => const LocalPlatform());
context.putIfAbsent(FileSystem, () => const LocalFileSystem());

View File

@ -38,7 +38,7 @@ const List<String> _kRequiredOptions = const <String>[
Future<Null> main(List<String> args) async {
final AppContext executableContext = new AppContext();
executableContext.setVariable(Logger, new StdoutLogger());
executableContext.runInZone(() {
await executableContext.runInZone(() {
// Initialize the context with some defaults.
context.putIfAbsent(Platform, () => const LocalPlatform());
context.putIfAbsent(FileSystem, () => const LocalFileSystem());

View File

@ -73,7 +73,7 @@ class LogsCommand extends FlutterCommand {
// Wait for the log reader to be finished.
final int result = await exitCompleter.future;
subscription.cancel();
await subscription.cancel();
if (result != 0)
throwToolExit('Error listening to $logReader logs.');
}

View File

@ -340,7 +340,8 @@ class RunCommand extends RunCommandBase {
//
// Do not add more operations to the future.
final Completer<Null> appStartedTimeRecorder = new Completer<Null>.sync();
appStartedTimeRecorder.future.then(
// This callback can't throw.
appStartedTimeRecorder.future.then( // ignore: unawaited_futures
(_) { appStartedTime = clock.now(); }
);

View File

@ -286,7 +286,8 @@ class _DevFSHttpWriter {
} catch (e) {
if (retry < kMaxRetries) {
printTrace('Retrying writing "$deviceUri" to DevFS due to error: $e');
_scheduleWrite(deviceUri, content, retry + 1);
// Synchronization is handled by the _completer below.
_scheduleWrite(deviceUri, content, retry + 1); // ignore: unawaited_futures
return;
} else {
printError('Error writing "$deviceUri" to DevFS: $e');

View File

@ -142,11 +142,12 @@ Future<String> getCodeSigningIdentityDevelopmentTeam({BuildableIOSApp iosApp, bo
..close();
final String opensslOutput = await UTF8.decodeStream(opensslProcess.stdout);
opensslProcess.stderr.drain<String>();
// Fire and forget discard of the stderr stream so we don't hold onto resources.
// Don't care about the result.
opensslProcess.stderr.drain<String>(); // ignore: unawaited_futures
if (await opensslProcess.exitCode != 0) {
if (await opensslProcess.exitCode != 0)
return null;
}
return _certificateOrganizationalUnitExtractionPattern
.firstMatch(opensslOutput)

View File

@ -237,7 +237,7 @@ class IOSSimulator extends Device {
Future<bool> installApp(ApplicationPackage app) async {
try {
final IOSApp iosApp = app;
SimControl.instance.install(id, iosApp.simulatorBundlePath);
await SimControl.instance.install(id, iosApp.simulatorBundlePath);
return true;
} catch (e) {
return false;
@ -382,7 +382,7 @@ class IOSSimulator extends Device {
printError('Error waiting for a debug connection: $error');
return new LaunchResult.failed();
} finally {
observatoryDiscovery.cancel();
await observatoryDiscovery.cancel();
}
}
@ -556,7 +556,9 @@ class _IOSSimulatorLogReader extends DeviceLogReader {
_systemProcess.stderr.transform(UTF8.decoder).transform(const LineSplitter()).listen(_onSystemLine);
}
_deviceProcess.exitCode.whenComplete(() {
// We don't want to wait for the process or its callback. Best effort
// cleanup in the callback.
_deviceProcess.exitCode.whenComplete(() { // ignore: unawaited_futures
if (_linesController.hasListener)
_linesController.close();
});

View File

@ -99,8 +99,10 @@ class FlutterDevice {
if (flutterViews == null || flutterViews.isEmpty)
return;
for (FlutterView view in flutterViews) {
if (view != null && view.uiIsolate != null)
view.uiIsolate.flutterExit();
if (view != null && view.uiIsolate != null) {
// Manage waits specifically below.
view.uiIsolate.flutterExit(); // ignore: unawaited_futures
}
}
await new Future<Null>.delayed(const Duration(milliseconds: 100));
}
@ -563,8 +565,9 @@ abstract class ResidentRunner {
}
Future<Null> stopEchoingDeviceLog() async {
for (FlutterDevice device in flutterDevices)
device.stopEchoingDeviceLog();
await Future.wait(
flutterDevices.map((FlutterDevice device) => device.stopEchoingDeviceLog())
);
}
/// If the [reloadSources] parameter is not null the 'reloadSources' service
@ -591,7 +594,10 @@ abstract class ResidentRunner {
// Listen for service protocol connection to close.
for (FlutterDevice device in flutterDevices) {
for (VMService service in device.vmServices) {
service.done.then<Null>(
// This hooks up callbacks for when the connection stops in the future.
// We don't want to wait for them. We don't handle errors in those callbacks'
// futures either because they just print to logger and is not critical.
service.done.then<Null>( // ignore: unawaited_futures
_serviceProtocolDone,
onError: _serviceProtocolError
).whenComplete(_serviceDisconnected);

View File

@ -42,7 +42,10 @@ class CoverageCollector extends TestWatcher {
final int pid = process.pid;
int exitCode;
process.exitCode.then<Null>((int code) {
// Synchronization is enforced by the API contract. Error handling
// synchronization is done in the code below where `exitCode` is checked.
// Callback cannot throw.
process.exitCode.then<Null>((int code) { // ignore: unawaited_futures
exitCode = code;
});
if (exitCode != null)

View File

@ -153,7 +153,8 @@ class _FlutterPlatform extends PlatformPlugin {
bool subprocessActive = false;
bool controllerSinkClosed = false;
try {
controller.sink.done.whenComplete(() { controllerSinkClosed = true; });
// Callback can't throw since it's just setting a variable.
controller.sink.done.whenComplete(() { controllerSinkClosed = true; }); // ignore: unawaited_futures
// Prepare our WebSocket server to talk to the engine subproces.
final HttpServer server = await HttpServer.bind(host, 0);
@ -272,7 +273,8 @@ class _FlutterPlatform extends PlatformPlugin {
subprocessActive = false;
final String message = _getErrorMessage(_getExitCodeMessage(exitCode, 'before connecting to test harness'), testPath, shellPath);
controller.sink.addError(message);
controller.sink.close();
// Awaited for with 'sink.done' below.
controller.sink.close(); // ignore: unawaited_futures
printTrace('test $ourTestCount: waiting for controller sink to close');
await controller.sink.done;
break;
@ -280,7 +282,8 @@ class _FlutterPlatform extends PlatformPlugin {
printTrace('test $ourTestCount: timed out waiting for process with pid ${process.pid} to connect to test harness');
final String message = _getErrorMessage('Test never connected to test harness.', testPath, shellPath);
controller.sink.addError(message);
controller.sink.close();
// Awaited for with 'sink.done' below.
controller.sink.close(); // ignore: unawaited_futures
printTrace('test $ourTestCount: waiting for controller sink to close');
await controller.sink.done;
break;
@ -332,8 +335,10 @@ class _FlutterPlatform extends PlatformPlugin {
testDone.future.then<_TestResult>((Null _) { return _TestResult.testBailed; }),
]);
harnessToTest.cancel();
testToHarness.cancel();
await Future.wait(<Future<Null>>[
harnessToTest.cancel(),
testToHarness.cancel(),
]);
switch (testResult) {
case _TestResult.crashed:
@ -342,7 +347,8 @@ class _FlutterPlatform extends PlatformPlugin {
subprocessActive = false;
final String message = _getErrorMessage(_getExitCodeMessage(exitCode, 'before test harness closed its WebSocket'), testPath, shellPath);
controller.sink.addError(message);
controller.sink.close();
// Awaited for with 'sink.done' below.
controller.sink.close(); // ignore: unawaited_futures
printTrace('test $ourTestCount: waiting for controller sink to close');
await controller.sink.done;
break;
@ -384,7 +390,8 @@ class _FlutterPlatform extends PlatformPlugin {
}
}
if (!controllerSinkClosed) {
controller.sink.close();
// Waiting below with await.
controller.sink.close(); // ignore: unawaited_futures
printTrace('test $ourTestCount: waiting for controller sink to close');
await controller.sink.done;
}