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

Commit

Permalink
refactor removeAll to use remove
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan committed Feb 4, 2019
1 parent e666e18 commit 7226850
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/keepkeyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,22 @@ 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 = {}
return Promise.all(Object.keys(this.keepkeys).map((deviceId) =>
this.remove(deviceId)))
.then(() => undefined) // don't return an array
}

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

0 comments on commit 7226850

Please sign in to comment.