File tree Expand file tree Collapse file tree 2 files changed +15
-10
lines changed
lib/ff/ruby/server/sdk/api Expand file tree Collapse file tree 2 files changed +15
-10
lines changed Original file line number Diff line number Diff line change 5
5
6
6
class CfClient < Closeable
7
7
include Singleton
8
-
8
+
9
+ @@instance_mutex = Mutex . new
9
10
def init ( api_key , config , connector = nil )
10
11
# Only initialize if @client is nil to avoid reinitialization
11
- unless @client
12
- @config = config || ConfigBuilder . new . build
13
- @client = InnerClient . new ( api_key , @config , connector )
14
- @config . logger . debug "Client initialized with API key: #{ api_key } "
12
+
13
+ @@instance_mutex . synchronize do
14
+ unless @client
15
+ @config = config || ConfigBuilder . new . build
16
+ @client = InnerClient . new ( api_key , @config , connector )
17
+ @config . logger . debug "Client initialized with API key: #{ api_key } "
18
+ end
15
19
end
16
20
@client
17
21
end
Original file line number Diff line number Diff line change @@ -120,9 +120,11 @@ def on_auth_success
120
120
end
121
121
122
122
def on_auth_failed
123
- SdkCodes ::warn_auth_failed_srv_defaults @config . logger
124
- @initialized = true
125
- @condition . signal
123
+ @my_mutex . synchronize do
124
+ SdkCodes ::warn_auth_failed_srv_defaults @config . logger
125
+ @initialized = true
126
+ @condition . broadcast
127
+ end
126
128
end
127
129
128
130
def close
@@ -243,7 +245,7 @@ def on_processor_ready(processor)
243
245
244
246
SdkCodes . info_sdk_init_ok @config . logger
245
247
246
- @condition . signal
248
+ @condition . broadcast
247
249
@initialized = true
248
250
end
249
251
end
@@ -257,7 +259,6 @@ def wait_for_initialization(timeout: nil)
257
259
remaining = timeout ? timeout / 1000.0 : nil # Convert timeout to seconds
258
260
259
261
until @initialized
260
-
261
262
# Break if timeout has elapsed
262
263
if remaining && remaining <= 0
263
264
@config . logger . warn "The SDK has timed out waiting to initialize with supplied timeout #{ timeout } ms. The SDK will continue to initialize in the background. Default variations will be served until the SDK initializes."
You can’t perform that action at this time.
0 commit comments