Fix 'Timed out waiting for device' error
Summary: It looks like this timeout was firing every time, causing a misleading error. Fixing by clearing it when the match is found. Reviewed By: passy Differential Revision: D19602640 fbshipit-source-id: b5d97e71a02a014b9498dd56371c1a48f8ae08eb
This commit is contained in:
committed by
Facebook Github Bot
parent
40ac443386
commit
060e8c0e93
@@ -202,6 +202,8 @@ export default class Client extends EventEmitter {
|
|||||||
}
|
}
|
||||||
reportPlatformFailures(
|
reportPlatformFailures(
|
||||||
new Promise<BaseDevice>((resolve, reject) => {
|
new Promise<BaseDevice>((resolve, reject) => {
|
||||||
|
let unsubscribe: () => void = () => {};
|
||||||
|
|
||||||
const device = this.store
|
const device = this.store
|
||||||
.getState()
|
.getState()
|
||||||
.connections.devices.find(
|
.connections.devices.find(
|
||||||
@@ -212,7 +214,13 @@ export default class Client extends EventEmitter {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsubscribe = this.store.subscribe(() => {
|
const timeout = setTimeout(() => {
|
||||||
|
unsubscribe();
|
||||||
|
const error = `Timed out waiting for device for client ${this.id}`;
|
||||||
|
console.error(error);
|
||||||
|
reject(error);
|
||||||
|
}, 5000);
|
||||||
|
unsubscribe = this.store.subscribe(() => {
|
||||||
const newDeviceList = this.store.getState().connections.devices;
|
const newDeviceList = this.store.getState().connections.devices;
|
||||||
if (newDeviceList === this.lastSeenDeviceList) {
|
if (newDeviceList === this.lastSeenDeviceList) {
|
||||||
return;
|
return;
|
||||||
@@ -222,16 +230,11 @@ export default class Client extends EventEmitter {
|
|||||||
device => device.serial === this.query.device_id,
|
device => device.serial === this.query.device_id,
|
||||||
);
|
);
|
||||||
if (matchingDevice) {
|
if (matchingDevice) {
|
||||||
|
clearTimeout(timeout);
|
||||||
resolve(matchingDevice);
|
resolve(matchingDevice);
|
||||||
unsubscribe();
|
unsubscribe();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
setTimeout(() => {
|
|
||||||
unsubscribe();
|
|
||||||
const error = `Timed out waiting for device for client ${this.id}`;
|
|
||||||
console.error(error);
|
|
||||||
reject(error);
|
|
||||||
}, 5000);
|
|
||||||
}),
|
}),
|
||||||
'client-setMatchingDevice',
|
'client-setMatchingDevice',
|
||||||
).then(device => {
|
).then(device => {
|
||||||
|
|||||||
Reference in New Issue
Block a user