Skip to content

Commit

Permalink
feat!: STALE returns last-seen value
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziodemaria committed Dec 2, 2024
1 parent 5b3d62a commit 1c5c9dc
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions Sources/Confidence/FlagEvaluation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ extension FlagResolution {
flagApplier: FlagApplier? = nil,
debugLogger: DebugLogger? = nil
) -> Evaluation<T> {
if self.context != context {
return Evaluation(
value: defaultValue,
variant: nil,
reason: .stale,
errorCode: nil,
errorMessage: nil
)
}
do {
let parsedKey = try FlagPath.getPath(for: flagName)
let resolvedFlag = self.flags.first { resolvedFlag in resolvedFlag.flag == parsedKey.flag }
Expand Down Expand Up @@ -80,14 +71,18 @@ extension FlagResolution {
let typedValue: T? = getTyped(value: parsedValue)

if resolvedFlag.resolveReason == .match {
var resolveReason: ResolveReason = .match
if self.context != context {
resolveReason = .stale
}
if let typedValue = typedValue {
Task {
await flagApplier?.apply(flagName: parsedKey.flag, resolveToken: self.resolveToken)
}
return Evaluation(
value: typedValue,
variant: resolvedFlag.variant,
reason: resolvedFlag.resolveReason,
reason: resolveReason,
errorCode: nil,
errorMessage: nil
)
Expand All @@ -100,7 +95,7 @@ extension FlagResolution {
return Evaluation(
value: defaultValue,
variant: resolvedFlag.variant,
reason: resolvedFlag.resolveReason,
reason: resolveReason,
errorCode: nil,
errorMessage: nil
)
Expand Down

0 comments on commit 1c5c9dc

Please sign in to comment.