Class: EventMeter::Stores::LockRefresher

Inherits:
Object
  • Object
show all
Defined in:
lib/event_meter/stores/lock_refresher.rb

Constant Summary collapse

JOIN_TIMEOUT =
1.0

Instance Method Summary collapse

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 = 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

#stopObject



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