Skip to content

Commit

Permalink
Fix 'try again' logics
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Oct 11, 2023
1 parent 0a669aa commit 5e9f2b4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/PTPDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum PTPType {
const PTPCommandMaxByteLength = 12 + 4 * 3
const PTPDefaultTimeoutMs = 10000
const PTPTryCount = 30
const PTPTryAgainIntervalMs = 500
const PTPTryAgainIntervalMs = 100

interface PTPSendCommandOption {
label?: string
Expand Down Expand Up @@ -233,7 +233,7 @@ export class PTPDevice extends EventEmitter<EventTypes> {
res.code === ResCode.DeviceBusy

if (tryAgain) {
sleep(PTPTryAgainIntervalMs)
await sleep(PTPTryAgainIntervalMs)
continue
}

Expand Down Expand Up @@ -283,7 +283,7 @@ export class PTPDevice extends EventEmitter<EventTypes> {
res.code === ResCode.DeviceBusy

if (tryAgain) {
sleep(PTPTryAgainIntervalMs)
await sleep(PTPTryAgainIntervalMs)
continue
}

Expand Down Expand Up @@ -347,7 +347,7 @@ export class PTPDevice extends EventEmitter<EventTypes> {
res2.code === ResCode.DeviceBusy

if (tryAgain) {
sleep(PTPTryAgainIntervalMs)
await sleep(PTPTryAgainIntervalMs)
continue
}

Expand Down
3 changes: 2 additions & 1 deletion src/Tethr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ export abstract class Tethr

for (const [name, value] of sortedConfigs) {
// NOTE: this might be converted to parallel execution in the future
console.log('setting', name, value)
await this.set(name, value)

// The delay is necessary to avoid "busy" error
await sleep(50)
await sleep(25)
}
}

Expand Down

0 comments on commit 5e9f2b4

Please sign in to comment.