|
|
@ -2,6 +2,7 @@ |
|
|
|
import createSemaphore from 'semaphore' |
|
|
|
import type Transport from '@ledgerhq/hw-transport' |
|
|
|
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid' |
|
|
|
import { retry } from './promise' |
|
|
|
|
|
|
|
// all open to device must use openDevice so we can prevent race conditions
|
|
|
|
// and guarantee we do one device access at a time. It also will handle the .close()
|
|
|
@ -17,7 +18,7 @@ export const withDevice: WithDevice = devicePath => { |
|
|
|
|
|
|
|
return job => |
|
|
|
takeSemaphorePromise(sem, async () => { |
|
|
|
const t = await TransportNodeHid.open(devicePath) |
|
|
|
const t = await retry(() => TransportNodeHid.open(devicePath), { maxRetry: 1 }) |
|
|
|
try { |
|
|
|
const res = await job(t) |
|
|
|
// $FlowFixMe
|
|
|
|