Fix adb client use of promise.resolve
Summary: This was misusing promise.resolve by calling it before the result is produced, meaning there was a race condition. It would also resolve as success even if listDevices failed. Reviewed By: passy Differential Revision: D13121173 fbshipit-source-id: f120a1b199d1e3168059c537461f65a8dc125a94
This commit is contained in:
committed by
Facebook Github Bot
parent
a6765deec6
commit
018718244a
@@ -55,14 +55,12 @@ function getRunningEmulatorName(id: string): Promise<?string> {
|
|||||||
|
|
||||||
export default (store: Store, logger: Logger) => {
|
export default (store: Store, logger: Logger) => {
|
||||||
// Using this client before adb server is started up will cause failures.
|
// Using this client before adb server is started up will cause failures.
|
||||||
// safeClient gets around this by waiting for listDevices first, which ensures
|
// this gets around this by waiting for listDevices first, which ensures
|
||||||
// the server is up and running.
|
// the server is up and running before allowing any other operations.
|
||||||
|
const clientPromise = (() => {
|
||||||
const unsafeClient = adb.createClient();
|
const unsafeClient = adb.createClient();
|
||||||
|
return unsafeClient.listDevices().then(() => unsafeClient);
|
||||||
const safeClient = () =>
|
})();
|
||||||
new Promise((resolve, reject) => {
|
|
||||||
resolve(unsafeClient.listDevices().then(() => unsafeClient));
|
|
||||||
});
|
|
||||||
|
|
||||||
const watchAndroidDevices = () => {
|
const watchAndroidDevices = () => {
|
||||||
// get emulators
|
// get emulators
|
||||||
@@ -81,7 +79,7 @@ export default (store: Store, logger: Logger) => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
safeClient().then(client => {
|
clientPromise.then(client => {
|
||||||
client
|
client
|
||||||
.trackDevices()
|
.trackDevices()
|
||||||
.then(tracker => {
|
.then(tracker => {
|
||||||
|
|||||||
Reference in New Issue
Block a user