From 7a810261face10fc9e4e4a617d3cd8a0a0d8b0e2 Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Mon, 7 May 2018 10:35:09 +0100 Subject: [PATCH] Only wait up to 3 seconds for emulator Emaultor keeps running on a seuccessful launch, so this automatically returns after 3 seconds if the process hasn't quit (we have to wait for some period to get stderr in the case of a failure). --- .../lib/src/android/android_emulator.dart | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/flutter_tools/lib/src/android/android_emulator.dart b/packages/flutter_tools/lib/src/android/android_emulator.dart index 5553446dfb..c8cec6d24f 100644 --- a/packages/flutter_tools/lib/src/android/android_emulator.dart +++ b/packages/flutter_tools/lib/src/android/android_emulator.dart @@ -42,12 +42,20 @@ class AndroidEmulator extends Emulator { @override Future launch() async { - final RunResult launchResult = - await runAsync([getEmulatorPath(), '-avd', id]); - - if (launchResult.exitCode != 0) { - printError('$launchResult'); - } + final Future launchResult = + runAsync([getEmulatorPath(), '-avd', id]) + .then((RunResult runResult) { + if (runResult.exitCode != 0) { + printError('$runResult'); + } + }); + // emulator continues running on a successful launch so if we + // haven't quit within 3 seconds we assume that's a success and just + // return. + await Future.any(>[ + launchResult, + new Future.delayed(const Duration(seconds: 3)) + ]); } }