class Droid::Monitor::Timer::Executor

Attributes

interval[R]

Public Class Methods

new(interval) click to toggle source

@param [int] interval Interval to wait

# File lib/droid/monitor/common/timer.rb, line 10
def initialize(interval)
  @interval = interval
end

Public Instance Methods

execute() { || ... } click to toggle source

@param [Block] &block Yield the block after sleep @interval @return [Symbol] :finished

# File lib/droid/monitor/common/timer.rb, line 16
def execute
  sleep interval
  yield

  :finished
end
execute_loop(&block) click to toggle source

Loop `execute` until stopping its process @param [Block] &block Yield the block after sleep @interval @return [Symbol] :finished

# File lib/droid/monitor/common/timer.rb, line 26
def execute_loop(&block)
  loop { execute(&block) }
end
execute_loop_thread(&block) click to toggle source

Start

t = timer.execute_loop_thread { puts "#{Time.now}" }

Stop

timer.kill_thread t

Loop `execute` until stopping its process on the other thread @param [Block] &block Yield the block after sleep @interval @return [Symbol] :finished

# File lib/droid/monitor/common/timer.rb, line 38
def execute_loop_thread(&block)
  Thread.new { loop { execute(&block) } }
end
kill_thread(thread) click to toggle source

@param [Thread] thread Kill the thread

# File lib/droid/monitor/common/timer.rb, line 43
def kill_thread(thread)
  Thread.kill thread
end
thread_list() click to toggle source

@return [Array] Return a list running thread on the process

# File lib/droid/monitor/common/timer.rb, line 48
def thread_list
  Thread.list
end