Skip to content

Commit d6ea811

Browse files
committed
refactor: use interval to check if emulator is booted
1 parent ba53509 commit d6ea811

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

packages/platform-android/src/commands/runAndroid/tryLaunchEmulator.ts

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ const launchEmulator = async (emulatorName: string, adbPath: string) => {
1919
[`@${emulatorName}`],
2020
{
2121
detached: true,
22-
stdio: ['ignore', 'pipe', 'ignore'],
22+
stdio: 'ignore',
2323
},
2424
);
25-
25+
cp.unref();
2626
const timeout = 30;
2727

2828
// Reject command after timeout
@@ -31,30 +31,18 @@ const launchEmulator = async (emulatorName: string, adbPath: string) => {
3131
reject(`Could not start emulator within ${timeout} seconds.`);
3232
}, timeout * 1000);
3333

34-
// When emulator is started from snapshot, it does not emit boot completed message.
35-
// It starts immediately so we can check if device is present after some short delay
36-
const snapshotStartTimeout = setTimeout(() => {
34+
const bootCheckInterval = setInterval(() => {
3735
if (Adb.getDevices(adbPath).length > 0) {
3836
cleanup();
3937
resolve();
4038
}
41-
}, 5000);
39+
}, 1000);
4240

4341
const cleanup = () => {
4442
clearTimeout(rejectTimeout);
45-
clearTimeout(snapshotStartTimeout);
46-
cp.stdout.destroy();
43+
clearInterval(bootCheckInterval);
4744
};
4845

49-
cp.unref();
50-
51-
cp.stdout.addListener('data', message => {
52-
if (message.toString().includes('boot completed')) {
53-
cleanup();
54-
resolve();
55-
}
56-
});
57-
5846
cp.on('exit', () => {
5947
cleanup();
6048
reject('Emulator exited before boot.');

0 commit comments

Comments
 (0)