Skip to content

Commit 9feac67

Browse files
author
Inbal Tako
committed
Add support for lazy singleton
1 parent b4bc855 commit 9feac67

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

lib/securenative/event_manager.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def initialize(url, body, retry_sending)
1212
end
1313

1414
class EventManager
15+
attr_reader :activated
16+
1517
def initialize(options = Options.new, http_client = nil)
1618
if options.api_key.nil?
1719
raise SecureNativeSDKError, 'API key cannot be None, please get your API key from SecureNative console.'
@@ -31,7 +33,8 @@ def initialize(options = Options.new, http_client = nil)
3133
@attempt = 0
3234
@coefficients = [1, 1, 2, 3, 5, 8, 13]
3335

34-
@thread = Thread.new { run }
36+
@activated = false
37+
@thread = nil
3538
end
3639

3740
def send_async(event, resource_path)
@@ -40,6 +43,11 @@ def send_async(event, resource_path)
4043
return
4144
end
4245

46+
unless @activated
47+
@thread = Thread.new { run }
48+
@activated = true
49+
end
50+
4351
item = QueueItem.new(resource_path, EventManager.serialize(event).to_json, false)
4452
@queue.append(item)
4553
end

0 commit comments

Comments
 (0)