Extract reenumerate() as an async function in reenumerate.js
This commit is contained in:
@@ -23,8 +23,10 @@ if (enumerationModeId === undefined) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`Trying to reenumerate as ${enumerationMode}...`);
|
||||
setInterval(() => {
|
||||
function reenumerate(enumerationModeId, bootloaderTimeoutMs) {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log(`Trying to reenumerate as ${enumerationMode}...`);
|
||||
const intervalId = setInterval(() => {
|
||||
pollingTimeoutMs -= pollingIntervalMs;
|
||||
|
||||
const foundDevice = HID.devices().find(device =>
|
||||
@@ -32,12 +34,16 @@ setInterval(() => {
|
||||
|
||||
if (foundDevice) {
|
||||
console.log(`${enumerationMode} is up`);
|
||||
process.exit(0);
|
||||
resolve();
|
||||
clearInterval(intervalId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pollingTimeoutMs <= 0) {
|
||||
console.log(`Couldn't reenumerate as ${enumerationMode}`);
|
||||
process.exit(1);
|
||||
reject();
|
||||
clearInterval(intervalId);
|
||||
return;
|
||||
}
|
||||
|
||||
let device = uhk.getUhkDevice();
|
||||
@@ -48,4 +54,10 @@ setInterval(() => {
|
||||
jumped = true;
|
||||
}
|
||||
|
||||
}, pollingIntervalMs);
|
||||
}, pollingIntervalMs);
|
||||
})
|
||||
};
|
||||
|
||||
(async function() {
|
||||
await reenumerate(enumerationModeId, bootloaderTimeoutMs);
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user