Class: Rubish::Job::ThreadJob
- Inherits:
-
Rubish::Job
- Object
- Rubish::Job
- Rubish::Job::ThreadJob
- Defined in:
- lib/rubish/job.rb
Overview
carry out some computation in a thread.
Instance Attribute Summary collapse
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Attributes inherited from Rubish::Job
Instance Method Summary collapse
-
#initialize(&block) ⇒ ThreadJob
constructor
A new instance of ThreadJob.
- #stop ⇒ Object
- #wait ⇒ Object
Methods inherited from Rubish::Job
Constructor Details
#initialize(&block) ⇒ ThreadJob
Returns a new instance of ThreadJob.
64 65 66 67 68 69 70 |
# File 'lib/rubish/job.rb', line 64 def initialize(&block) # run block in a thread @thread = ::Thread.new { block.call } __start end |
Instance Attribute Details
#thread ⇒ Object (readonly)
Returns the value of attribute thread.
63 64 65 |
# File 'lib/rubish/job.rb', line 63 def thread @thread end |
Instance Method Details
#stop ⇒ Object
85 86 87 88 |
# File 'lib/rubish/job.rb', line 85 def stop @thread.kill wait end |