Use Promise.race instead so both promises do not resolve

This commit is contained in:
Josh Perez 2023-05-15 11:08:15 -04:00 committed by GitHub
parent 7a71c6ab80
commit f6676db4d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -167,6 +167,7 @@ export function SmartInstallScreen(): ReactElement {
useEffect(() => {
let hasCleanedUp = false;
const qrCodeResolution = explodePromise<void>();
const accountManager = window.getAccountManager();
assertDev(accountManager, 'Expected an account manager');
@ -175,6 +176,7 @@ export function SmartInstallScreen(): ReactElement {
if (hasCleanedUp) {
return;
}
qrCodeResolution.resolve();
setProvisioningUrl(value);
};
@ -227,7 +229,8 @@ export function SmartInstallScreen(): ReactElement {
);
const sleepMs = qrCodeBackOff.getAndIncrement();
log.info(`InstallScreen/getQRCode: race to ${sleepMs}ms`);
await pTimeout(qrCodePromise, sleepMs, sleepError);
await pTimeout(qrCodeResolution.promise, sleepMs, sleepError);
await qrCodePromise;
window.IPC.removeSetupMenuItems();
} catch (error) {