@stoprocent/noble 2.3.5 → 2.3.6
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
|
@@ -188,10 +188,12 @@ class Noble extends EventEmitter {
|
|
|
188
188
|
const self = this;
|
|
189
189
|
const scan = (state) => {
|
|
190
190
|
if (state !== 'poweredOn') {
|
|
191
|
-
|
|
191
|
+
const boundScan = scan.bind(self);
|
|
192
|
+
self.once('stateChange', boundScan);
|
|
192
193
|
const error = new Error(`Could not start scanning, state is ${state} (not poweredOn)`);
|
|
193
194
|
|
|
194
195
|
if (typeof callback === 'function') {
|
|
196
|
+
self.removeListener('stateChange', boundScan);
|
|
195
197
|
callback(error);
|
|
196
198
|
} else {
|
|
197
199
|
throw error;
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/test/noble.test.js
CHANGED
|
@@ -184,6 +184,24 @@ describe('noble', () => {
|
|
|
184
184
|
);
|
|
185
185
|
expect(mockBindings.startScanning).not.toHaveBeenCalled();
|
|
186
186
|
});
|
|
187
|
+
|
|
188
|
+
test('should not cause MaxListenersExceededWarning warnings after repeated unauthorized errors', async () => {
|
|
189
|
+
noble._state = 'unauthorized';
|
|
190
|
+
|
|
191
|
+
const promise = noble.waitForPoweredOnAsync(0);
|
|
192
|
+
|
|
193
|
+
for (let i = 0; i < 10; i++) {
|
|
194
|
+
try {
|
|
195
|
+
await noble.startScanningAsync([]);
|
|
196
|
+
} catch (error) {
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const finalListenerCount = noble.listenerCount('stateChange');
|
|
201
|
+
|
|
202
|
+
await expect(promise).rejects.toThrow('Timeout waiting for Noble to be powered on');
|
|
203
|
+
expect(finalListenerCount).toBeLessThanOrEqual(1);
|
|
204
|
+
});
|
|
187
205
|
});
|
|
188
206
|
|
|
189
207
|
describe('stopScanning', () => {
|
|
@@ -421,7 +439,7 @@ describe('noble', () => {
|
|
|
421
439
|
await expect(promise).rejects.toThrow('Timeout waiting for Noble to be powered on');
|
|
422
440
|
});
|
|
423
441
|
|
|
424
|
-
test('should not cause MaxListenersExceededWarning with multiple timeout calls', async () => {
|
|
442
|
+
test('should not cause MaxListenersExceededWarning warnings with multiple timeout calls', async () => {
|
|
425
443
|
noble._state = 'poweredOff';
|
|
426
444
|
|
|
427
445
|
const promises = [];
|