Class: ThreadWatcher::ThreadHolder
- Inherits:
-
Object
- Object
- ThreadWatcher::ThreadHolder
- Defined in:
- lib/thread_watcher/thread_holder.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#id ⇒ Object
Returns the value of attribute id.
-
#options ⇒ Object
Returns the value of attribute options.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#thread ⇒ Object
Returns the value of attribute thread.
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(block, options) ⇒ ThreadHolder
constructor
A new instance of ThreadHolder.
- #restart! ⇒ Object
- #runtime ⇒ Object
- #start! ⇒ Object
- #stop! ⇒ Object
- #time_to_i ⇒ Object
Constructor Details
#initialize(block, options) ⇒ ThreadHolder
Returns a new instance of ThreadHolder.
4 5 6 7 8 |
# File 'lib/thread_watcher/thread_holder.rb', line 4 def initialize block, @block = block set_id = .merge end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
3 4 5 |
# File 'lib/thread_watcher/thread_holder.rb', line 3 def block @block end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/thread_watcher/thread_holder.rb', line 3 def id @id end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/thread_watcher/thread_holder.rb', line 3 def end |
#start_time ⇒ Object
Returns the value of attribute start_time.
3 4 5 |
# File 'lib/thread_watcher/thread_holder.rb', line 3 def start_time @start_time end |
#thread ⇒ Object
Returns the value of attribute thread.
3 4 5 |
# File 'lib/thread_watcher/thread_holder.rb', line 3 def thread @thread end |
Instance Method Details
#alive? ⇒ Boolean
24 25 26 |
# File 'lib/thread_watcher/thread_holder.rb', line 24 def alive? @thread.alive? end |
#restart! ⇒ Object
19 20 21 22 |
# File 'lib/thread_watcher/thread_holder.rb', line 19 def restart! stop! start! end |
#runtime ⇒ Object
28 29 30 |
# File 'lib/thread_watcher/thread_holder.rb', line 28 def runtime time_to_i - start_time end |
#start! ⇒ Object
10 11 12 13 |
# File 'lib/thread_watcher/thread_holder.rb', line 10 def start! initialize_starttime @thread = Thread.new{ block.call } end |
#stop! ⇒ Object
15 16 17 |
# File 'lib/thread_watcher/thread_holder.rb', line 15 def stop! @thread.kill end |
#time_to_i ⇒ Object
32 33 34 |
# File 'lib/thread_watcher/thread_holder.rb', line 32 def time_to_i Time.now.to_i end |