Skip to content
Open
Show file tree
Hide file tree
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
27 changes: 27 additions & 0 deletions Dayflow/Dayflow/Core/Recording/RecorderRecoveryPolicy.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Foundation

enum RecorderRecoveryPolicy {
static func canCommitSetup(
setupGeneration: Int,
currentGeneration: Int,
isStarting: Bool
) -> Bool {
isStarting && setupGeneration == currentGeneration
}

static func retryDelay(forNoDisplayAttempt attempt: Int, maxAttempts: Int) -> TimeInterval? {
guard attempt > 0, attempt < maxAttempts else { return nil }
return pow(2, Double(attempt - 1))
}

static func shouldRestartAfterWake(
isCapturing: Bool,
hasDisplay: Bool,
lastSuccessfulCaptureAt: Date?,
now: Date,
staleAfter: TimeInterval
) -> Bool {
guard isCapturing, hasDisplay, let lastSuccessfulCaptureAt else { return true }
return now.timeIntervalSince(lastSuccessfulCaptureAt) > staleAfter
}
}
Loading