Class: Rubish::JobControl
- Inherits:
-
Object
- Object
- Rubish::JobControl
- Defined in:
- lib/rubish/job_control.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ JobControl
constructor
A new instance of JobControl.
- #jobs ⇒ Object
- #remove(job) ⇒ Object
-
#submit(job) ⇒ Object
need to synchronize access to the jobs hash.
- #wait(*jobs) ⇒ Object
-
#waitall(&block) ⇒ Object
TODO handle interrupt.
Constructor Details
#initialize ⇒ JobControl
Returns a new instance of JobControl.
17 18 19 20 |
# File 'lib/rubish/job_control.rb', line 17 def initialize @mutex = Mutex.new @jobs = { } end |
Class Method Details
Instance Method Details
#jobs ⇒ Object
22 23 24 |
# File 'lib/rubish/job_control.rb', line 22 def jobs @jobs.values end |
#remove(job) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/rubish/job_control.rb', line 34 def remove(job) raise "expects a Rubish::JobControl::Job" unless job.is_a?(Rubish::Job) raise Rubish::Error.new("Job not found: #{job}") unless @jobs.include?(job.object_id) @mutex.synchronize { @jobs.delete(job.object_id) } end |
#submit(job) ⇒ Object
need to synchronize access to the jobs hash
27 28 29 30 31 32 |
# File 'lib/rubish/job_control.rb', line 27 def submit(job) raise "expects a Rubish::JobControl::Job" unless job.is_a?(Rubish::Job) @mutex.synchronize { @jobs[job.object_id] = job } end |
#wait(*jobs) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rubish/job_control.rb', line 42 def wait(*jobs) rss = jobs.map do |job| job.wait if block_given? yield(job) else job end end return *rss end |
#waitall(&block) ⇒ Object
TODO handle interrupt
55 56 57 |
# File 'lib/rubish/job_control.rb', line 55 def waitall(&block) wait(*@jobs.values,&block) end |