-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathstatus_manager.rb
More file actions
39 lines (31 loc) · 1008 Bytes
/
status_manager.rb
File metadata and controls
39 lines (31 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true
module SplitIoClient
module Engine
class StatusManager
def initialize(config, internal_events_queue)
@config = config
@sdk_ready = Concurrent::CountDownLatch.new(1)
@internal_events_queue = internal_events_queue
end
def ready?
return true if @config.consumer?
@sdk_ready.wait(0)
end
def ready!
return if ready?
@sdk_ready.count_down
@config.logger.info('SplitIO SDK is ready')
@internal_events_queue.push(
SplitIoClient::Engine::Models::SdkInternalEventNotification.new(
SplitIoClient::Engine::Models::SdkInternalEvent::SDK_READY, nil
)
)
end
def wait_until_ready(seconds = nil)
return if @config.consumer?
timeout = seconds || @config.block_until_ready
raise SDKBlockerTimeoutExpiredException, 'SDK start up timeout expired' unless @sdk_ready.wait(timeout)
end
end
end
end