Method: UniqueThread#run

Defined in:
lib/unique_thread.rb

#run(&block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/unique_thread.rb', line 17

def run(&block)
  safe_infinite_loop do
    lock = locksmith.new_lock

    if lock.acquired?
      logger.info('Lock acquired! Running the unique thread.')
      lock.while_held(&block)
    else
      logger.debug('Could not acquire the lock. Sleeping until next attempt.')
      stopwatch.sleep_until_next_attempt(lock.locked_until.to_f)
    end
  end
end