Skip to content

Commit

Permalink
fix: satisfy jshints
Browse files Browse the repository at this point in the history
  • Loading branch information
stoprocent committed Feb 26, 2025
1 parent 03fd811 commit a7d39ae
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/uart.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* jshint esversion: 8 */

const EventEmitter = require('events');
const debug = require('debug')('hci-uart');
const { SerialPort } = require('serialport');
Expand Down Expand Up @@ -87,14 +89,15 @@ class BluetoothHciSocket extends EventEmitter {
this._handleReconnection(devId, params, mode, port, retryConnection);
});
}

async _handleReconnection (devId, params, mode, port, maxRetries) {
let retryCount = 0;
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
this._isReconnectionCancelled = false; // Reset cancellation flag on new attempt

while (retryCount < maxRetries && !this._isReconnectionCancelled) {
try {
const ports = await SerialPort.list();
/* jshint loopfunc: true */
const portExists = ports.some(p => p.path === port);

if (portExists) {
Expand All @@ -107,15 +110,15 @@ class BluetoothHciSocket extends EventEmitter {

retryCount++;
debug(`Retry ${retryCount}/${maxRetries} - Port ${port} not found`);
await new Promise(resolve => setTimeout(resolve, 1000)); // Wait 1 second
await delay(1000);
} catch (err) {
debug('Error listing ports:', err);
retryCount++;
if (retryCount >= maxRetries || this._isReconnectionCancelled) {
debug(`Reconnection stopped: ${this._isReconnectionCancelled ? 'Cancelled' : `Max retries (${maxRetries}) reached`} for port ${port}`);
return;
}
await new Promise(resolve => setTimeout(resolve, 1000)); // Wait 1 second on error
await delay(1000);
}
}

Expand Down

0 comments on commit a7d39ae

Please sign in to comment.