diff --git a/packages/connect/src/device/DeviceList.ts b/packages/connect/src/device/DeviceList.ts index ce261e51f99..7a271e2f603 100644 --- a/packages/connect/src/device/DeviceList.ts +++ b/packages/connect/src/device/DeviceList.ts @@ -268,9 +268,17 @@ export class DeviceList extends TypedEmitter 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 { @@ -351,12 +359,19 @@ export class DeviceList extends TypedEmitter 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() {