Sha256: c442927cf1753e8b3da94a2b3622f0bbe1d92938e374aed6db9fe021ae9f2a8f
Contents?: true
Size: 1.09 KB
Versions: 2
Compression:
Stored size: 1.09 KB
Contents
# A job is not necessarily registered with job # control. # TODO extend this for bg/fg (maybe?) # Assume that job control is used by a single thread... require 'thread' class Rubish::JobControl class << self def current Rubish::Context.current.job_control end end def initialize @mutex = Mutex.new @jobs = { } end def jobs @jobs.values end # need to synchronize access to the jobs hash def submit(job) raise "expects a Rubish::JobControl::Job" unless job.is_a?(Rubish::Job) @mutex.synchronize { @jobs[job.object_id] = job } end 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 def wait(*jobs) rss = jobs.map do |job| job.wait if block_given? yield(job) else job end end return *rss end # TODO handle interrupt def waitall(&block) wait(*@jobs.values,&block) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rubish-0.1.0 | lib/rubish/job_control.rb |
rubish-0.0.1 | lib/rubish/job_control.rb |