Class: ThreadWatcher::ThreadHolder

Inherits:
Object
  • Object
show all
Defined in:
lib/thread_watcher/thread_holder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options
  @block = block
  set_id
  @options = available_options.merge options
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



3
4
5
# File 'lib/thread_watcher/thread_holder.rb', line 3

def block
  @block
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/thread_watcher/thread_holder.rb', line 3

def id
  @id
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/thread_watcher/thread_holder.rb', line 3

def options
  @options
end

#start_timeObject

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

#threadObject

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

Returns:

  • (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

#runtimeObject



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_iObject



32
33
34
# File 'lib/thread_watcher/thread_holder.rb', line 32

def time_to_i
  Time.now.to_i
end