@stoprocent/noble 2.3.4 → 2.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/noble.js CHANGED
@@ -167,6 +167,7 @@ class Noble extends EventEmitter {
167
167
  return;
168
168
  }
169
169
  const timeoutId = setTimeout(() => {
170
+ this.removeListener('stateChange', listener);
170
171
  reject(new Error('Timeout waiting for Noble to be powered on'));
171
172
  }, timeout);
172
173
 
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "license": "MIT",
7
7
  "name": "@stoprocent/noble",
8
8
  "description": "A Node.js BLE (Bluetooth Low Energy) central library.",
9
- "version": "2.3.4",
9
+ "version": "2.3.5",
10
10
  "repository": {
11
11
  "type": "git",
12
12
  "url": "https://github.com/stoprocent/noble.git"
@@ -420,6 +420,19 @@ describe('noble', () => {
420
420
  // Promise should reject after timeout
421
421
  await expect(promise).rejects.toThrow('Timeout waiting for Noble to be powered on');
422
422
  });
423
+
424
+ test('should not cause MaxListenersExceededWarning with multiple timeout calls', async () => {
425
+ noble._state = 'poweredOff';
426
+
427
+ const promises = [];
428
+ for (let i = 0; i < 11; i++) {
429
+ promises.push(noble.waitForPoweredOnAsync(0).catch(() => {}));
430
+ }
431
+ await Promise.all(promises);
432
+ const finalListenerCount = noble.listenerCount('stateChange');
433
+
434
+ expect(finalListenerCount).toBeLessThanOrEqual(1);
435
+ });
423
436
  });
424
437
 
425
438
  test('should change address', () => {