-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Fabrizio Demaria <[email protected]>
- Loading branch information
1 parent
9ca2cc3
commit 12ad983
Showing
3 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import Foundation | ||
import OpenFeature | ||
import Combine | ||
|
||
class SlowProvider: FeatureProvider { | ||
public static let name = "Slow" | ||
private let eventHandler = EventHandler(.stale) | ||
private var holdit: AnyCancellable? | ||
|
||
func onContextSet(oldContext: OpenFeature.EvaluationContext?, newContext: OpenFeature.EvaluationContext) { | ||
eventHandler.send(.ready) | ||
} | ||
|
||
func initialize(initialContext: OpenFeature.EvaluationContext?) { | ||
Task { | ||
// TODO Remove the sleep in the tests | ||
print(">> Sleeping") | ||
try await Task.sleep(nanoseconds: 1_000_000_000) | ||
print(">> Emitting Ready") | ||
eventHandler.send(.ready) | ||
} | ||
} | ||
|
||
var hooks: [any OpenFeature.Hook] = [] | ||
var metadata: OpenFeature.ProviderMetadata = DoMetadata() | ||
|
||
func getBooleanEvaluation(key: String, defaultValue: Bool, context: EvaluationContext?) throws | ||
-> ProviderEvaluation< | ||
Bool | ||
> | ||
{ | ||
return ProviderEvaluation(value: !defaultValue) | ||
} | ||
|
||
func getStringEvaluation(key: String, defaultValue: String, context: EvaluationContext?) throws | ||
-> ProviderEvaluation< | ||
String | ||
> | ||
{ | ||
return ProviderEvaluation(value: String(defaultValue.reversed())) | ||
} | ||
|
||
func getIntegerEvaluation(key: String, defaultValue: Int64, context: EvaluationContext?) throws | ||
-> ProviderEvaluation< | ||
Int64 | ||
> | ||
{ | ||
return ProviderEvaluation(value: defaultValue * 100) | ||
} | ||
|
||
func getDoubleEvaluation(key: String, defaultValue: Double, context: EvaluationContext?) throws | ||
-> ProviderEvaluation< | ||
Double | ||
> | ||
{ | ||
return ProviderEvaluation(value: defaultValue * 100) | ||
} | ||
|
||
func getObjectEvaluation(key: String, defaultValue: Value, context: EvaluationContext?) throws | ||
-> ProviderEvaluation< | ||
Value | ||
> | ||
{ | ||
return ProviderEvaluation(value: .null) | ||
} | ||
|
||
func observe() -> CurrentValueSubject<ProviderEvent, Never> { | ||
eventHandler.observe() | ||
} | ||
|
||
public struct DoMetadata: ProviderMetadata { | ||
public var name: String? = DoSomethingProvider.name | ||
} | ||
} |