Skip to content

Commit

Permalink
[CP-3128] FlashStatusType provided
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarski committed Oct 10, 2024
1 parent 6e7cb74 commit 984ac21
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import IDeviceFlash, {
waitForFlashCompletionOption,
} from "../device-flash.interface"

type FlashStatusType =
| "FLASH_STATUS_COMPLETED"
| "FLASH_STATUS_FAILED"
| "FLASH_STATUS_IDLE"

interface DeviceDetails {
[key: string]: string | undefined

Expand Down Expand Up @@ -86,6 +91,7 @@ class MacDeviceFlashService implements IDeviceFlash {
async waitForFlashCompletion(
option: waitForFlashCompletionOption = {}
): Promise<boolean> {
let flashStatus: FlashStatusType = "FLASH_STATUS_IDLE"
const { intervalAttemptsLeft = 60, intervalTime = 5000, signal } = option

if (intervalAttemptsLeft <= 0 || signal?.aborted) {
Expand All @@ -94,13 +100,17 @@ class MacDeviceFlashService implements IDeviceFlash {

try {
const buffer = fs.readFileSync(this.flashStatusTempFilePath)
if (buffer.toString().trim() === "true") {
return true
}
flashStatus = buffer.toString().trim() as FlashStatusType
} catch (error) {
console.error(`Error reading file: ${JSON.stringify(error)}. Retrying...`)
}

if (flashStatus === "FLASH_STATUS_COMPLETED") {
return true
} else if (flashStatus === "FLASH_STATUS_FAILED") {
throw new Error()
}

await delay(intervalTime)

return this.waitForFlashCompletion({
Expand Down

0 comments on commit 984ac21

Please sign in to comment.