Skip to content

Commit

Permalink
build: Bump to OpenFeature SDK 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziodemaria committed Feb 5, 2024
1 parent 500d84e commit d6f12d3
Show file tree
Hide file tree
Showing 5 changed files with 674 additions and 510 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "[email protected]:open-feature/swift-sdk.git",
"state": {
"branch": null,
"revision": "114321e376b3d80e6623c5cbd7e8bcef9c6a86d2",
"version": "0.0.2"
"revision": "02b033c954766e86d5706bfc8ee5248244c11e77",
"version": "0.1.0"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let package = Package(
targets: ["ConfidenceProvider"])
],
dependencies: [
.package(url: "[email protected]:open-feature/swift-sdk.git", from: "0.0.2"),
.package(url: "[email protected]:open-feature/swift-sdk.git", from: "0.1.0"),
],
targets: [
.target(
Expand Down
18 changes: 12 additions & 6 deletions Sources/ConfidenceProvider/ConfidenceFeatureProvider.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Foundation
import OpenFeature
import Combine
import os

/// The implementation of the Confidence Feature Provider. This implementation allows to pre-cache evaluations.
Expand All @@ -19,6 +20,7 @@ public class ConfidenceFeatureProvider: FeatureProvider {
private let flagApplier: FlagApplier
private let initializationStrategy: InitializationStrategy
private let storage: Storage
private let eventHandler = EventHandler(ProviderEvent.notReady)

/// Should not be called externally, use `ConfidenceFeatureProvider.Builder` instead.
init(
Expand Down Expand Up @@ -49,7 +51,7 @@ public class ConfidenceFeatureProvider: FeatureProvider {

// signal the provider is ready right away
if self.initializationStrategy == .activateAndFetchAsync {
OpenFeatureAPI.shared.emitEvent(.ready, provider: self)
eventHandler.send(.ready)
}

Task {
Expand All @@ -65,11 +67,11 @@ public class ConfidenceFeatureProvider: FeatureProvider {

// signal the provider is ready after the network request is done
if self.initializationStrategy == .fetchAndActivate {
OpenFeatureAPI.shared.emitEvent(.ready, provider: self)
eventHandler.send(.ready)
}
} catch {
// We emit a ready event as the provider is ready, but is using default / cache values.
OpenFeatureAPI.shared.emitEvent(.ready, provider: self)
eventHandler.send(.ready)
}
}
}
Expand Down Expand Up @@ -105,9 +107,9 @@ public class ConfidenceFeatureProvider: FeatureProvider {

// update the storage
try await store(with: newContext, resolveResult: resolveResult, refreshCache: true)
OpenFeatureAPI.shared.emitEvent(.ready, provider: self)
eventHandler.send(ProviderEvent.ready)
} catch {
OpenFeatureAPI.shared.emitEvent(.ready, provider: self)
eventHandler.send(ProviderEvent.ready)
// do nothing
}
}
Expand Down Expand Up @@ -163,6 +165,10 @@ public class ConfidenceFeatureProvider: FeatureProvider {
errorPrefix: "Error during object evaluation for key \(key)")
}

public func observe() -> AnyPublisher<OpenFeature.ProviderEvent, Never> {
return eventHandler.observe()
}

/// Allows you to override directly on the provider. See `overrides` on ``Builder`` for more information.
///
/// For example
Expand All @@ -179,7 +185,7 @@ public class ConfidenceFeatureProvider: FeatureProvider {

private func resolve(context: OpenFeature.EvaluationContext) async throws -> ResolvesResult {
// Racy: eval ctx and ctx in cache might differ until the latter is updated, resulting in STALE evaluations
OpenFeatureAPI.shared.emitEvent(.stale, provider: self)
eventHandler.send(ProviderEvent.stale)
do {
let resolveResult = try await client.resolve(ctx: context)
return resolveResult
Expand Down
Loading

0 comments on commit d6f12d3

Please sign in to comment.