Class: Concurrent::TimerTask
- Inherits:
-
Object
- Object
- Concurrent::TimerTask
- Includes:
- Dereferenceable, Runnable, Observable
- Defined in:
- lib/concurrent/timer_task.rb
Constant Summary collapse
- EXECUTION_INTERVAL =
60- TIMEOUT_INTERVAL =
30
Constants included from Runnable
Instance Attribute Summary collapse
-
#execution_interval ⇒ Object
Returns the value of attribute execution_interval.
-
#timeout_interval ⇒ Object
Returns the value of attribute timeout_interval.
Instance Method Summary collapse
-
#initialize(opts = {}, &block) ⇒ TimerTask
constructor
A new instance of TimerTask.
- #kill ⇒ Object (also: #terminate)
Methods included from Runnable
included, #run, #run!, #running?, #stop
Methods included from Dereferenceable
Constructor Details
#initialize(opts = {}, &block) ⇒ TimerTask
Returns a new instance of TimerTask.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/concurrent/timer_task.rb', line 21 def initialize(opts = {}, &block) raise ArgumentError.new('no block given') unless block_given? @execution_interval = opts[:execution] || opts[:execution_interval] || EXECUTION_INTERVAL @timeout_interval = opts[:timeout] || opts[:timeout_interval] || TIMEOUT_INTERVAL @run_now = opts[:now] || opts[:run_now] || false @task = block (opts) end |
Instance Attribute Details
#execution_interval ⇒ Object
Returns the value of attribute execution_interval.
18 19 20 |
# File 'lib/concurrent/timer_task.rb', line 18 def execution_interval @execution_interval end |
#timeout_interval ⇒ Object
Returns the value of attribute timeout_interval.
19 20 21 |
# File 'lib/concurrent/timer_task.rb', line 19 def timeout_interval @timeout_interval end |
Instance Method Details
#kill ⇒ Object Also known as: terminate
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/concurrent/timer_task.rb', line 32 def kill return true unless running? mutex.synchronize do @running = false Thread.kill(@worker) unless @worker.nil? Thread.kill(@monitor) unless @monitor.nil? end return true rescue return false ensure @worker = @monitor = nil end |