Skip to content
This repository has been archived by the owner on Aug 7, 2019. It is now read-only.

refactor removeAll to use remove #26

Merged
merged 1 commit into from
Feb 5, 2019
Merged
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
18 changes: 10 additions & 8 deletions src/keepkeyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,20 @@ export default class KeepKeyManager {

public async remove (deviceID: string): Promise<void> {
if (!this.keepkeys[deviceID]) return
const keepkey = this.get(deviceID)
await keepkey.clearSession()
await keepkey.device.disconnect()

try {
const keepkey = this.get(deviceID)
await keepkey.clearSession()
await keepkey.device.disconnect()
} catch (e) {
console.error(e)
}

delete this.keepkeys[deviceID]
}

public async removeAll (): Promise<void> {
Object.values(this.keepkeys).forEach(async (keepkey) => {
await keepkey.clearSession()
await keepkey.device.disconnect()
})
this.keepkeys = {}
await Promise.all(Object.keys(this.keepkeys).map(this.remove))
}

public decorateEvents (deviceID: string, events: eventemitter2.EventEmitter2): void {
Expand Down