Skip to content

Commit

Permalink
fix(connect): ignore disposed error in devicelist
Browse files Browse the repository at this point in the history
  • Loading branch information
martykan committed Dec 3, 2024
1 parent 6a86971 commit 6877cc0
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions packages/connect/src/device/DeviceList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,17 @@ export class DeviceList extends TypedEmitter<DeviceListEvents> implements IDevic
const { promise, reject } = resolveAfter(1000, initParams);
this.rejectPending = reject;

return promise.then(this.createInitPromise.bind(this)).finally(() => {
this.rejectPending = undefined;
});
return promise
.then(this.createInitPromise.bind(this))
.catch(error => {
if (error.message === 'Disposed') {
return;
}
throw error;
})
.finally(() => {
this.rejectPending = undefined;
});
}

private async selectTransport([transport, ...rest]: Transport[]): Promise<Transport> {
Expand Down Expand Up @@ -351,12 +359,19 @@ export class DeviceList extends TypedEmitter<DeviceListEvents> implements IDevic
this.on(DEVICE.CONNECT, onDeviceConnect);
this.on(DEVICE.CONNECT_UNACQUIRED, onDeviceConnect);

return promise.finally(() => {
this.rejectPending = undefined;
clearTimeout(autoResolveTransportEventTimeout);
this.off(DEVICE.CONNECT, onDeviceConnect);
this.off(DEVICE.CONNECT_UNACQUIRED, onDeviceConnect);
});
return promise
.catch(error => {
if (error.message === 'Disposed') {
return;
}
throw error;
})
.finally(() => {
this.rejectPending = undefined;
clearTimeout(autoResolveTransportEventTimeout);
this.off(DEVICE.CONNECT, onDeviceConnect);
this.off(DEVICE.CONNECT_UNACQUIRED, onDeviceConnect);
});
}

getDeviceCount() {
Expand Down

0 comments on commit 6877cc0

Please sign in to comment.