Class: EventMeter::Stores::LockRefresher
- Inherits:
-
Object
- Object
- EventMeter::Stores::LockRefresher
- Defined in:
- lib/event_meter/stores/lock_refresher.rb
Constant Summary collapse
- JOIN_TIMEOUT =
1.0
Instance Method Summary collapse
-
#initialize(interval:, refresh:, failure_message:, thread_name:) ⇒ LockRefresher
constructor
A new instance of LockRefresher.
- #start(owner: Thread.current) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(interval:, refresh:, failure_message:, thread_name:) ⇒ LockRefresher
Returns a new instance of LockRefresher.
8 9 10 11 12 13 14 15 16 |
# File 'lib/event_meter/stores/lock_refresher.rb', line 8 def initialize(interval:, refresh:, failure_message:, thread_name:) @interval = interval @refresh = refresh @failure_message = @thread_name = thread_name @mutex = Mutex.new @condition = ConditionVariable.new @stopped = false end |
Instance Method Details
#start(owner: Thread.current) ⇒ Object
18 19 20 21 22 |
# File 'lib/event_meter/stores/lock_refresher.rb', line 18 def start(owner: Thread.current) @owner = owner @thread = Thread.new { run } self end |
#stop ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/event_meter/stores/lock_refresher.rb', line 24 def stop @mutex.synchronize do @stopped = true @condition.broadcast end @thread&.join(JOIN_TIMEOUT) end |