Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/noble.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class Noble extends EventEmitter {
return;
}
const timeoutId = setTimeout(() => {
this.removeListener('stateChange', listener);
reject(new Error('Timeout waiting for Noble to be powered on'));
}, timeout);

Expand Down
13 changes: 13 additions & 0 deletions test/noble.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,19 @@ describe('noble', () => {
// Promise should reject after timeout
await expect(promise).rejects.toThrow('Timeout waiting for Noble to be powered on');
});

test('should not cause MaxListenersExceededWarning with multiple timeout calls', async () => {
noble._state = 'poweredOff';

const promises = [];
for (let i = 0; i < 11; i++) {
promises.push(noble.waitForPoweredOnAsync(0).catch(() => {}));
}
await Promise.all(promises);
const finalListenerCount = noble.listenerCount('stateChange');

expect(finalListenerCount).toBeLessThanOrEqual(1);
});
});

test('should change address', () => {
Expand Down
Loading