Skip to content

Commit d219951

Browse files
feat: [add load function to EppoClient] (FF-2907) (#39)
* feat: [add `load` function to EppoClient] (FF-2907) * typo in comment
1 parent e80c0df commit d219951

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ public class AssignmentObserver: ObservableObject {
102102
}
103103
```
104104

105-
106105
Rendering the view:
107106

108107
```swift

Sources/eppo/EppoClient.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation;
22

33
// todo: make this a build argument (FF-1944)
44
public let sdkName = "ios"
5-
public let sdkVersion = "3.0.1"
5+
public let sdkVersion = "3.1.0"
66

77
public enum Errors: Error {
88
case notConfigured
@@ -99,6 +99,14 @@ public class EppoClient {
9999
}
100100
return instance
101101
}
102+
103+
// Loads the configuration from the remote source on-demand. Can be used to refresh as desired.
104+
//
105+
// This function can be called from multiple threads; synchronization is provided to safely update
106+
// the configuration cache but each invocation will execute a new network request with billing impact.
107+
public func load() async throws {
108+
try await self.configurationStore.fetchAndStoreConfigurations()
109+
}
102110

103111
public static func resetSharedInstance() {
104112
sharedInstance = nil

Tests/eppo/SingletonTest.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,27 @@ final class EppoTests: XCTestCase {
4747
XCTAssertIdentical(eppoClient1, eppoClient2, "Changing host re-instantiates the singleton")
4848
}
4949

50+
func testLoadingMultithreading() async throws {
51+
let expectedCount = 50
52+
let expectation = XCTestExpectation(description: "eppo client expectation")
53+
expectation.expectedFulfillmentCount = expectedCount
54+
55+
Task {
56+
await withThrowingTaskGroup(of: Void.self) { group in
57+
for _ in 0 ..< expectedCount {
58+
group.addTask {
59+
_ = try await EppoClient.initialize(sdkKey: "mock-api-key")
60+
_ = try await EppoClient.shared().load()
61+
expectation.fulfill()
62+
}
63+
}
64+
}
65+
}
66+
67+
await fulfillment(of: [expectation], timeout: 5)
68+
XCTAssertEqual(stubCallCount, 51) // initialize + 50 `load` executions
69+
}
70+
5071
func testEppoClientMultithreading() async throws {
5172
let expectedCount = 50
5273
let expectation = XCTestExpectation(description: "eppo client expectation")

0 commit comments

Comments
 (0)